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.

5 Answers 5

3

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

Thanks

Sign up to request clarification or add additional context in comments.

1 Comment

This will work quite well for what I want to do. Here is a link with more info: stackoverflow.com/questions/427180/…
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.

Comments

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.

Comments

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

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.