Rename file on upload

edited June 2012 in Modules
Hi,
Is it possible to specify a target file name when using an image upload field in form_fields()?

I'd like to be able to save images on the server under a specific name (i.e. image_$id.jpg). If the only way to do this is through a hook, can someone give me a simple example of the code they would use in the hook?

Thanks!

Comments

  • edited 11:36AM
    You can pass the parameter "filename" to the "file" type upload field. If you have a field that ends with "image" or "img" and it automatically creates the text field and upload field, make sure to target the file upload field in your form_fields method like so:
    .... $fields['image_upload']['filename'] = 'my_new_filename';

    If the name is dependent on another fields value, say a field named "client", you can use "{client}" as a placeholder like so:
    .... $fields['image_upload']['filename'] = '{client}_my_new_filename';
  • edited June 2012
    Thanks admin! That was exactly what I was looking for.

    Keep up the excellent work! The more I use Fuel, the more I realize how great it is. Not only is Fuel a solid piece of work but you, sir, are an amazingly available and competent resource for this community you've built. Kudos to you!
  • edited 11:36AM
    Thank you maxbel... stay tuned for some much needed update announcements at the end of this month.
Sign In or Register to comment.