I'm working on an iPhone app that will upload images to a web server. I was wondering if anyone had any tips on how to generate unique names for each image file that gets uploaded. I'm sure there are a million ways to do this, but if anyone has any suggestions I'd really appreciate it! Thanks.
5 Answers
you could create a GUID and save the image as that name ..
Thanks
1 Comment
Jeff
This will work quite well for what I want to do. Here is a link with more info: stackoverflow.com/questions/427180/…
You could use the unix timestamp. This would allow you to update a record with a new file while still keeping the same id, instead of having to create a new record each time a file is changed. Some like:
$uploadData = pathinfo($_FILES['file']['tmp_name']);
move_uploaded_file($_FILES['file']['tmp_name'], time() . '.' . $uploadData['extension']);
I'd recommend a lot more checking to ensure the file is what you are looking for, such as mime type/extension checking, max size, and ensure the file is an uploaded file using is_uploaded_file().