houssam_ballout Posted April 18, 2010 Share Posted April 18, 2010 Hello, I had a form in which users can upload their photos, but if 2 files had the same name, then it won't upload. I need to make the file names, something like the one downloaded from facebook (in which filenames can get their string name using some php code) which is a lengthy. Any help? Thanks Link to comment https://forums.phpfreaks.com/topic/198947-generate-unique-string/ Share on other sites More sharing options...
TeddyKiller Posted April 18, 2010 Share Posted April 18, 2010 $_SESSION['id'] . time() . $filename; example 111249231941myimage.jpg Although you might want to stick some hypens between id, time and filename. So you can use an explode to seperate it and get the actual image name Link to comment https://forums.phpfreaks.com/topic/198947-generate-unique-string/#findComment-1044289 Share on other sites More sharing options...
houssam_ballout Posted April 18, 2010 Author Share Posted April 18, 2010 I need more explanation for that its a simple website for uploading images, why do I need session? Link to comment https://forums.phpfreaks.com/topic/198947-generate-unique-string/#findComment-1044330 Share on other sites More sharing options...
TeddyKiller Posted April 19, 2010 Share Posted April 19, 2010 The session is the logged in users id. (Will need to be changed to suit your needs) So.. for definately more than 1 user cannot have the same file uploaded, as it'll have the users unique ID in it. As for the time() this gives it a unique timestamp, for the sake of duplication of the image. (Users may have the same filename on two images for example, the timestamp will allow users can upload 2 pics with the same filename) Link to comment https://forums.phpfreaks.com/topic/198947-generate-unique-string/#findComment-1044381 Share on other sites More sharing options...
houssam_ballout Posted April 19, 2010 Author Share Posted April 19, 2010 I will try to use the time stamp & file name, cause I don't have a place for users to login. Thanks Link to comment https://forums.phpfreaks.com/topic/198947-generate-unique-string/#findComment-1044472 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.