Hello!

I have a question regarding your fine image upload module. I could use some good advice regarding control over the name of the uploaded image file. By default the uploaded file's name is not altered but determined by the user. What I want to do is to rename the file according to my needs, but I don't know where to start.
In my scenaio the file's name will be depending on the content of another CCK field.

Possible starting points:

- Drupal API: Maybe one can hook into the upload process (if used by imagefield resp. filefield) to control the file name.
- imagefield/filefield hacking: err... probably the worst option.
- Tokens: As I see, imagefield/filefield makes use of tokens to manipulate the path where the file is saved. Is there any chance to use this mechanism for the file name, too?

The formal stuff:
CCK version: 6.x-2.0-rc6
imagefield version: 6.x-3.0-alpha1
The rest is not so relevant here, I think.

Thanks in advance and best regards,
Henry

Comments

IngusNeilands’s picture

Subscribe

pre911mindset’s picture

I use image and not imagefield, not sure if they work the same way. It should work to use hook_insert to override the base filename in the node structure, from your own module if you go that route.

mgorla’s picture

Subscribe

It could perhaps be useful to insert a "name template" field, which can compose the name of the file on uploading with:
- usern ame
- file name
- content type name
- title of the image (somehow purged by spaces and bad chars)
- custom

So I can obtain different filenames:
- user_file.jpg
- content_user_file.jpg
- user_title.jpg
- content_title.jpg
etc

:)

illuminaut’s picture

subscribe

illuminaut’s picture

I found out that if you use the filefield-paths module it lets you change path and file names using tokens. This works for both filefield and imagefield, so it should address your need. I've been trying it out and it works great.

zmove’s picture

Hi,

I'm subscribing this feature too. But not really the same than filefield-path propose..

It would be good to have the possibility to add an additionnal "filename" field into imagefield setting, or more generally filefield setting as this feature request can apply to all files...

If this field is empty when uploading a picture, keep the original filename. If the field is filled, change the name of the image.

This is an usefull feature IMHO because you often don't want the same filenames in your website than in your hard drive. Or maybe this is not you that generate the image or something else... That's why a renaming feature would be very cool.

basicmagic.net’s picture

subscribe

quicksketch’s picture

Status: Active » Closed (fixed)

illuminaut makes the best suggestion: Use the FileField Paths module if you need to rename files on upload. I don't think ImageField (or FileField) will provide this ability directly.

oxford-dev’s picture

Status: Closed (fixed) » Active

I would like to open this again as I think having to install another module with all of it's bells and whistles consuming resources when all I want is a very simple function is not the right course of action.

In comment #2 hook_insert is mentioned, would someone please be able to elaborate on this?

What i'm after is very simple, change the name of the file from its original to the uploaders uid.

Example:

Instead of /files/avatars/myphoto.jpg

have /files/avatars/2.jpg if user 2 uploaded the file.

This would only happen on a particular cck field.

I'm sure there must be a simpler solution to this??

Many thanks

quicksketch’s picture

Status: Active » Closed (won't fix)

ImageField has been moved into core and no new features are being added. You'll have to depend on other modules for new functionality.