Possible Duplicate:
PHP: How to generate a random, unique, alphanumeric string?
Trying to get something like https://i.stack.imgur.com/3fB75.jpg
We know that imgur uses 5 case sensitive string for image. How to do it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could just use your auto_increment image id, converted to base58 (a-zA-Z0-9) for example.
base_convertcan convert up to base36:(See also PHP – How to base_convert() up to base 62)
If you want non-predictable image ids, look at this answer.
For MongoDB IDs (as you are using MongoDB):
The ids are 12 bytes numbers, encoded to base16, which makes them 24 bytes.
You can compress them to 17 bytes by converting them from base16 to base58:
Also take a look at the Sequence Numbers section here. This will allow you to generate smaller unique numbers for your images.