It would be really helpful if I could rename file uploads with information from other form fields -- i.e. if the form has basic personal info plus a file upload for a headshot, the file would be renamed something like LastName_FirstName.

Comments

sunahsuh’s picture

This would also solve collision errors where users overwrite each other's files in the directory if they have the same filename -- for instance, a filename like resume.doc is quite common for a resume upload.

quicksketch’s picture

This is very unlikely to be implemented. If needing complex renaming of files, you'll need to create a custom module to handle it. You might take a look at how Transliteration module cleans up the names of files on upload.

charles_wisniewski’s picture

This would be a very helpful module, I am currently working on some hack-job version of it, if anyone can implement, 100 kudos

quicksketch’s picture

File upload collisions are already solved by Drupal. If two items with the same name are uploaded, the second one gets "resume_0.doc", then "resume_1.doc", etc.

lex0r’s picture

Issue tags: +file, +renaming, +uploading

Another good feature would be automatic naming according to predefined pattern. For example,

User file: A very long and ugly filename.doc
Rename mask = file-xxxx.doc, automatic counter = on
Resulting file: file-0001.doc

Who's first to implement? :)

fivehimself’s picture

You could create this with CCK, Token and File field. I have it setup, so when uploading an attachment to a node, the file is renamed to the-title-of-the-node.ext.

I needed this because people kept uploading files that contained spaces, &*()%$#@!/ in their filenames. Now I have nice clean url's that also match the posts title.

quicksketch’s picture

I needed this because people kept uploading files that contained spaces, &*()%$#@!/ in their filenames.

You should simply install Transliteration module to fix this particular problem.

fivehimself’s picture

I know, but I also wanted to order all uploads in a nice structure. Giving them a place related to the post type and title.

But you're right, If I'd only wanted to cleanup there's an easier way.

albert volkman’s picture

@fivehimself: Could you please detail how you did this? It's exactly what I need to do!

albert volkman’s picture

Nevermind, I was able to take care of my issue using http://drupal.org/project/filefield_paths

chorrylan’s picture

fivehimself and avolkman .... did you get this to work on a webform?

I've used filefield_path to control attachments to nodes but I can't see how to use it for the webform file component.

(and I can't see how to get either core attachments or a CCK filefield working with a webform)

fivehimself’s picture

I didn't use webform.... so I can't help you with that.

seattlehimay’s picture

Subscribing. I would also find this feature useful.

lukus’s picture

Subscribing

albert volkman’s picture

I didn't use webform either :-/

mrfelton’s picture

I think this would be a useful addition to webform too. Use case:

Webform is being used to submit entries to a competition. For each entry there is an attached file which needs to be renamed on upload to include the submission id (sid) in the filename. This makes it much easier to administer the submissions.

mossill’s picture

thank you @Albert Volkman. This module is what I was looking 4. peace !

boftx’s picture

Version: » 6.x-3.0-beta5

Subscribing.

One approach might be to allow the use of tokens in the path field. For my purposes, it would be very helpful to place uploads in a directory structure based on UID and NID. This would reduce directory size and clutter.

michelle’s picture

Version: 6.x-3.0-beta5 » 6.x-3.x-dev

I need this as well. Anyone come up with anything in the last 4 months?

Michelle

michelle’s picture

Ok, Quicksketch's mention of the Transliteration module was the key here. If anyone is looking to do this, here's what I did:

/**
 * Implementation of hook_init().
 *
 * Adjust file name in competition upload.
 */
function laccmods_init() {
   if (!empty($_FILES['files']) && !empty($_POST['submitted']['category'])) {
    foreach ($_FILES['files']['name'] as $field => $filename) {
      // Keep a copy of the unaltered file name.
      $_FILES['files']['orig_name'][$field] = $filename;
      $_FILES['files']['name'][$field] = laccmods_competition_filename($_POST['submitted']);
    }
  }
}

$_POST['submitted'] contains all the other stuff on the form. That custom module just uses that to created a new filename and sends it back.

The first line checks for the existence of "category" which lets me know this is the file I'm interested in.

If you use Transliteration, make sure you weight your site module higher or it will make changes to your adjusted file name.

This has had only minimal testing so far as I just finished it 5 minutes ago. Be sure to do your own testing.

Michelle

scott m. sanders’s picture

Subscribing

kim.pepper’s picture

Just installing the transliteration module helped me with an issue of double encoded spaces.

quicksketch’s picture

Status: Active » Closed (won't fix)

Per #2.

oliverpolden’s picture

I realise this is old but for anyone coming across this there is extra stuff you can do if you have the entity module. It includes the entity tokens module so you can do stuff like renaming an image file with the alt text.