rename the uploaded file

DesignWork - August 10, 2007 - 11:07
Project:ImageField
Version:6.x-3.0
Component:User interface
Category:feature request
Priority:normal
Assigned:Unassigned
Status:won't fix
Description

Hi Mantainers,

I would like to ask a question refering the imagefield (5x.1.1).
Is it possible to rename the uploaded file?
At the moment imagefield just takes the given filename and uses it. The problem is when you download the images to your desktop (drag and drop) the image has only the file name. I would like that it has the name of the user who posted the image and maybe the name of the website. like: misterx-mysite.jpg. This would very good for people researching the web they allways know where the image is from.

Maybe we could youse some code from autonode title and use the same tokens.

Thanks for replying

Dirk

PS. I can help coding it. Just wanted to change some ideas first.

#1

Waldemar - November 2, 2007 - 11:11

I would like to have this feature as well. It makes the filesystem much more organised. Any chance that this could be done? If there is no development time, I'd be happy to implement it, I just don't like patching unmaintained code by myself.

#2

Bencoon - December 10, 2007 - 15:56
Title:rename the uploded file» rename the uploaded file

(fixed typo)

I think this would be a great idea as well; particularly for those with galleries with heavy loads. An option to have uploaded files renamed, using tokens perhaps, thus minimizing the risk of overwriting a similarly-named image.

#3

dopry - December 18, 2007 - 03:57
Version:5.x-1.1» 6.x-3.x-dev

Nope not implemented. If you write it, do it for DRUPAL-5--2 or HEAD.

#4

smcguinness - December 31, 2007 - 16:44

Is this being written for 2? This would be fantastic.

#5

suketu.topiwala - January 3, 2008 - 12:54

Hey guys i am working on the same thing
hope will sort it out in day or two

#6

Serg_dj - January 4, 2008 - 22:59
Version:6.x-3.x-dev» 5.x-2.0-rc2

To rename file at upload time i use following code :

<?php
function _imagefield_widget_prepare_form_values(&$node, $field, &$items) {
 
$fieldname = $field['field_name'];
 
// clean up the session if we weren't posted.
 
if (!count($_POST)) {
   
imagefield_clear_session();
  }

 
// Attach new files
 
if ($file = file_check_upload($fieldname . '_upload')) {
   
$file = (array)$file;
   
   
//**** NEW CODE : replace filename with new generated ************************
    // allow tokenized paths.
   
if (function_exists('token_replace')) {
        global
$user;
       
$widget_image_path = token_replace($field['widget']['image_path'],'user', $user);
    }
    else {
       
$widget_image_path = $field['widget']['image_path'];
    }
   
$filepath = file_create_path($widget_image_path); // directory where file located
   
$file_ext = ereg_replace( "^.*(\\.[^.]*)$", "\\1", $file['filename']);
    do {
// generates new name
        
$rndname = mt_rand().$file_ext;
    }while (
file_check_location($rndname,$filepath));
   
$file['filename'] = $rndname;
   
//*************************************************************
   
    //...........
?>

#7

dopry - May 12, 2008 - 20:20
Status:active» won't fix

nope.. not taking that patch... My stance is rename files before uploading them...

#8

Mr.Alinaki - May 29, 2009 - 21:16
Version:5.x-2.0-rc2» 6.x-3.0

Is there any ideas how to implement this functionality without patch? It would be nice to see... Thanx.

 
 

Drupal is a registered trademark of Dries Buytaert.