Uploading files and renaming on the fly

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sinewave
Forum Commoner
Posts: 41
Joined: Tue Sep 10, 2002 4:35 pm
Location: Canada

Uploading files and renaming on the fly

Post by sinewave »

Dont worry, i understand how to upload files, but how can i rename them to something unique, and what is a good scheme for renaming pictures so there wont be duplicate names and can be added to a db. They will be added one at a time, so the names must come from somewhere. I'm not too sure

any advice?
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

I've done it with a datetime-stamp (yy)(mm)(dd)(hh)(mm)(ss). I didn't want a random-number - there should still be some kind of order to the images you upload (to my mind :p ).

Code: Select all

$documentfile=ereg_replace(" ","",$documenttitle).(string)date("YmdHis").".".$documentwildcard;
Example: "myImg.gif" will be "myImg200302072013222.gif

Basically every image will get an individual name every second(!). Make sure that on your form you catch double-clicking, i.e. double-submitting.
Post Reply