PHP Image Upload - Unique through microtime ()

If I make the file name of each uploaded microtime () PHPs file, are the collision risks realistic? And is there a way to further randomize file names?

I expect about 20,000 downloads in about a week. This is 2800 / day or 119 / hour (subject to uniform distribution). Does anyone have experience suggesting that micro-time will be unique?

Thanks!

+4
source share
3 answers

The best way to generate random file names in your case is to use a GUID . They are great because this algorithm guarantees the unification of values ​​even for multiple servers. If you use windows, the com_create_guid function is for you. You can also look at uniqid , which is available for all PHP platforms.

+5
source

One common method is to create directories in the format YYYY / MM / DD / id.jpg. Thus, you also do not face file system limitations.

+1
source

I think this is not a huuuuge problem. (paranoid view)

Just check if it exists, if it exists, resolve the conflict (possibly in a while loop until its unique is guaranteed).

I can not imagine so many files in a microsecond.

0
source

All Articles