Page 1 of 1
How do i stop overwriting of uploaded files?
Posted: Wed Feb 25, 2004 2:10 pm
by mikegotnaild
If my users upload a file with the same name as one that is already in the folder what type of coding do i have to do to stop this... I WANT to keep the file names in-tact though. Maybe i could have a folder automatically created for them and then put the files into that folder...?
Re: How do i stop overwriting of uploaded files?
Posted: Wed Feb 25, 2004 2:13 pm
by Roja
mikegotnaild wrote:If my users upload a file with the same name as one that is already in the folder what type of coding do i have to do to stop this... I WANT to keep the file names in-tact though. Maybe i could have a folder automatically created for them and then put the files into that folder...?
You could do something like:
APP_NAME-HHMM-FILENAME.EXT
So if your application was "webthing", then it could prepend the filename to include webthing, and the time it was saved. That way, very very few collisions.
Posted: Wed Feb 25, 2004 2:37 pm
by mikegotnaild
could i get a code example please?
Posted: Wed Feb 25, 2004 2:40 pm
by patrikG
Roja is refering to the date function, e.g.:
Alternatively, you could check whether the file exists already with
[php_man]file_exists[/php_man]. If true, then prompt user.
Posted: Wed Feb 25, 2004 4:28 pm
by mikegotnaild
Ok i did that but when i echo $filename it shows the date information. I need it to show the file name.