Hello,
How can I rename image before uploading. I first insert image path/name into DB and then image into a directory on server. Now, if two user comes on my site and one is male and other is female and they both uploaded their display pictures. First male uploads with the name male.jpg and then female uploads with the same name then it overwrites the image and users don't see their actual picture. I don't want to create new folder for each user. I just want to first get ID of image I just inserted into DB as its auto-incremental and then concate that id with the image name and then upload. e.g. image_1.jpg, image_2.jpg and so on.
Thank you so much
Aamir
How can I rename image before uploading?
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Well, select the max(`id`) from the database, and implement it by 1, and name the picture that.
Separate folders for each user is actually a good idea. Or, something that could almost guarantee a unique name for an image.
Something like...
Or, play around with uniqid()
Separate folders for each user is actually a good idea. Or, something that could almost guarantee a unique name for an image.
Something like...
Code: Select all
$img_name = time().substr(md5(microtime()), 0, rand(5,12)).$img_extension;thanks
i tried this and it works
i tried this and it works
Code: Select all
$id = 99;
$image = $id.'_'.$_FILES['image'][name];
$path = "testimage/";
if (move_uploaded_file($_FILES['image']['tmp_name'], $path.$image))