rename and upload mage file

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
vikaspa
Forum Newbie
Posts: 8
Joined: Tue Aug 31, 2004 12:30 am
Location: Mumbai,India

rename and upload mage file

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: rename and upload mage file

Post 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.
Post Reply