Subject: Renaming a file during upload
Posted By: keph Post Date: 9/28/2005 5:15:49 AM
Please do anyone know how I can rename a file while uploading it?
I posted this in the beginners forum and got not response.

===

This is my senario:
I upload form content into a database along with the file name of a picture file. Note, I store only the file name of the picture file in the database, the actuall file is stored in a folder on the server. This works perfectly.
However if two users have their picture files named the same way (e.g my_picture.jpg) only the first guy can upload. The second guy will have to change his file name or may actually end up deleting the first guys picture.
Is there a way I can dynamically rename pictures during the upload irrespective of what the user might have called his file?
Thanks all

http://www.kephassolutions.com
Reply By: Moharo Reply Date: 10/6/2005 7:14:51 PM
hey

that's no problem... all you have to do is generate certain file naming convention like so:

$new_filename = [userid] . "_" . microtime();

the renaming is done when you copy the file from $_POST array to folder like so:

<?php

copy($_FILES["image_upl"]["tmp_name"],[destination]);

?>

and that's it

if you are still not sure about this, let me know... peace

?>


www.campusgrind.com - college portal

Go to topic 35480

Return to index page 458
Return to index page 457
Return to index page 456
Return to index page 455
Return to index page 454
Return to index page 453
Return to index page 452
Return to index page 451
Return to index page 450
Return to index page 449