View Full Version : how to rename file at run time

08-02-2007, 08:16 AM
i have a php form , in which i have some controls. On a form there is a "File Field" control. When user select any file from browse button, the file will be uploaded successfully.

But i need some modifications.

I want that when user upload a new file, the php code rename the file and add some random string with the file name.

How can i do this, i spend many time on this module, but i am unable to do it.

Please help in this regard.

08-02-2007, 09:04 AM
I assume you are using copy() or move_uploaded_file() to move the temporary file (from $_FILES['fieldname']['tmp_name'] to somewhere else ?

if so simply rename there

$u=uniqid(mktime()); //thats a big filename ;) best revise
copy( $_FILES['fieldname']['tmp_name'] , '/home/blah/'.$u.$_FILES['fieldname']['name']);