1

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.

Jeff
  • 2,778
  • 3
  • 28
  • 31

5 Answers5

3

you could create a GUID and save the image as that name ..

Thanks

Sandyx
  • 76
  • 1
  • This will work quite well for what I want to do. Here is a link with more info: http://stackoverflow.com/questions/427180/how-to-create-a-guid-uuid-using-the-iphone-sdk – Jeff Mar 24 '09 at 17:45
2

The simplest solution (assuming you're storing these in a database) is to have an auto-increment field in the database, and use that to rename the file as it's uploaded. That way you'll end up with image00000001.jpg, image00000002.jpg, etc.

Mark Bessey
  • 19,321
  • 4
  • 46
  • 67
1

The simplest would be to convert the current time into a string and use that as a name. will always be unique :)

Or if you have a private key in your database, use it with a generic string to generate a unique name for each image.

lostInTransit
  • 69,487
  • 59
  • 196
  • 271
0

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().

Darryl Hein
  • 138,721
  • 89
  • 210
  • 259
0

You may want to consider using the device id of the generating phone to insure uniqueness across the universe of iPhones.

Jack Cox
  • 3,262
  • 22
  • 25