Page 1 of 1

changing the name on a binary upload

PostPosted: Thu Mar 01, 2012 1:02 pm
by wisni1rr
I was wondering how you could have the name of a file changed as it uploads?

For example:
I have a field that uploads a .pdf file to a directory on my server. I would like it so that it would rename the file using a field in my table so the new name would be $ID.pdf essentially.

The reason I ask is because if someone happens to upload a file that is named the same as another, it would overwrite the original .pdf file.

Thanks for taking the time to read my post!

Re: changing the name on a binary upload

PostPosted: Thu Mar 01, 2012 1:22 pm
by shannah
If someone uploads a file with the same name, it will rename the file being uploaded automatically by appending a numeric index to the name and/or incrementing it. It shouldn't overwrite when there is a collision.

As far as renaming it yourself, you could implement a beforeSave handler to rename the file and set the new name in the file field.

-Steve