Forums

CF4: Upload file name generating

menchee 28 Jan, 2012
In CF3, the name of the uploaded file was generated by PHP code.
Now, in CF4, I'm not sure how can I generate the name, except for using the some ready made values like {rand}, {datetime} etc.

For example, how can I strip white spaces from the original file name? Or how can I change the date format? These are just some examples.

Thanks,
Emanuel.
GreyHead 28 Jan, 2012
Hi Emanuel,

It looks as though you are using my Upload File [GH] action? If so, then you can use any entry from the $form->data array using {key} in the file name (where 'key' is a key from $form->data).

You can use a Custom Code action before the Upload Files action to set any value you like in the $form_data array.

The standard Files Upload action has a file-name filter at the bottom of the tab. I'll add that to the code next time I edit it. Meanwhile you can filter it with a Custom Code action as above.

Bob
menchee 28 Jan, 2012
Hi Bob,
Yes, I use your action file (Thanks!!!).

Currently, none of the keys is working for the name. Not even the input name (for example: {artist_photo} ) or the other I mentioned.

I understand your solution, I just have to make sure I can use any of the elements in the data array as a key.

Emanuel.
GreyHead 28 Jan, 2012
Hi Emanuale,

Ok - I'll go dig in the code in a while to see why it isn't working. Just have a tax return to complete first :-(

Bob
This topic is locked and no more replies can be posted.