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.

Comments

Waldemar’s picture

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.

Bencoon’s picture

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.

dopry’s picture

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.

smcguinness’s picture

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

snipe’s picture

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

Serg_dj’s picture

Version: 6.x-3.x-dev » 5.x-2.0-rc2

To rename file at upload time i use following code :

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;
	//*************************************************************
    
	//...........
dopry’s picture

Status: Active » Closed (won't fix)

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

mr.alinaki’s picture

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.

ecrown’s picture

Just incase someone is still looking for this.
this module does exactly that http://drupal.org/project/uploadpath