Possible Duplicate:
PHP: How to generate a random, unique, alphanumeric string?
Trying to get smth like http://imgur.com/t4Syk We know that imgur uses 5 case sensitive string for image. How to do it?
You could just use your auto_increment image id, converted to base58 (a-zA-Z0-9) for example.
base_convert
can convert up to base36:
$id = base_convert(123456789, 10, 36); // "21i3v9"
(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:
gmp_strval(gmp_init("47cc67093475061e3d95369d", 16), 58)); // "1KXotnQBQbcPmeOo9"
Also take a look at the Sequence Numbers section here. This will allow you to generate smaller unique numbers for your images.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With