H
H
happ2016-06-02 18:50:09
PHP
happ, 2016-06-02 18:50:09

How to generate a unique image name like in vk.com?

Using php, I need to generate a unique name for the image like in vk.com. For example, such kqE5rJR7GTs.jpg
Now I generate based on the current time, but I would like to see more options.

Answer the question

In order to leave comments, you need to log in

6 answer(s)
R
Rou1997, 2016-06-02
@happ

Yes, just a string of random characters - large, small letters and numbers, and for reinsurance, you can check whether it turned out to be unique, if not, then generate it again.

D
Dmitry, 2016-06-02
@thewind

PHP has a uniqid() function

M
Mikhail Osher, 2016-06-02
@miraage

php.net/manual/en/function.random-bytes.php

Андрей, 2016-06-02
@VladimirAndreev

SHA1(md5-сумма файла + MD5(текущее время)).

Сергей Новиков, 2016-06-02
@BOOMER_74

Как вариант, воспользоватся Hashids. Выглядит как случайная строка, но ее можно декодировать в числа (массив например, [1, 2, 3]). Удобно если нужна связь с БД.

P
profesor08, 2016-06-02
@profesor08

Take the id from the database. It's enough.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question