renaming a file while uploading it

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
hame22
Forum Contributor
Posts: 214
Joined: Wed May 11, 2005 5:50 am

renaming a file while uploading it

Post by hame22 »

I would like to rename a file as I upload it to the server, so as to give it a unique name, how can this be achieved?

Thanks in advance
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

I usually just md5() for a unique filename in combination with file_exists(), and simply use that value when using move_uploaded_file()
Last edited by John Cartwright on Wed Dec 06, 2006 9:02 am, edited 1 time in total.
User avatar
Skittlewidth
Forum Contributor
Posts: 389
Joined: Wed Nov 06, 2002 9:18 am
Location: Kent, UK

Post by Skittlewidth »

Use

Code: Select all

move_uploaded_file($tmpname, $destination)
and add or prefix a timestamp to the $destination filename?

Doh, you beat me to it Jcart!
Post Reply