Page 1 of 1

rename and upload mage file

Posted: Fri Dec 04, 2009 9:43 pm
by vikaspa
I am storing the upload user files for each user as follow


id, Image name, user_id

1, 456.jpg, 1
2, 456.jpg, 2
3, 884.jpg, 2
4, a111.jpg, 2


Suppose t 123.jpg do not exists on server
and user1 want to upload the 123.jpg

id, Image name, user_id
1, 123.jpg , 1

I will store this image name and image as it is

Suppose user5 wish to upload (the user is different here) a file whose name is also 123.jpg

I donot want to tell / inform user2 that the file 123.jpg exists

instead wish to store the image with different name
so that the earlier file name upload by the user1 will remain as it is

Storing original image name is not a issue here.

I like to ensure that the old / existing image should not be overwritten

Re: rename and upload mage file

Posted: Sat Dec 05, 2009 4:03 am
by requinix
The the original filename in the database, but rename the file (as it is stored on the server) with something unique.

For instance,

Code: Select all

$filename = $user_id . "-" . uniqid(time(), true) . "." . $extension;
Of course you'll be storing that $filename in the database too.