How to create a unique url for images (imgur.com like) in php?

Possible duplicate:
PHP: How to create a random, unique alphanumeric string?

Trying to get something like http://imgur.com/t4Syk We know that imgur uses 5 lowercase characters for the image. How to do it?

+8
php image
source share
1 answer

You can simply use your auto_increment image id, for example, converted to base58 (a-zA-Z0-9).

base_convert can convert to base36:

 $id = base_convert(123456789, 10, 36); // "21i3v9" 

(See also PHP - How to base_convert () to base 62 )

If you want non-predictable image identifiers, see this answer .


For MongoDB IDs (how do you use MongoDB):

An id is 12 bytes of 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 create smaller unique numbers for your images.

+11
source share

All Articles