PHP Image uploading - uniqueness via microtime()
If I make the filename of each uploaded file PHPs microtime(), are the risks of a collision realistic? And is there a way to further randomize the filenames?
I'm expecting about 20,000 uploads in about a week. That's 2800/day or 119/hour (assuming even distribution). Does anyone have any experience with assuming microtime to be开发者_开发技巧 unique?
Thanks!
The best way to generate random file names in your case is to use GUIDs. They are great because this algorithm guarantees uniqness of the value even for multiple server. If you are using windows the com_create_guid
function is for you.
Also you can look at uniqid
function which available for all PHP platforms.
One common method is to create directories in the format of YYYY/MM/DD/id.jpg. That way you don't run into file system limitations as well.
I think this is not a huuuuge problem. (kinda paranoid)
Just make a check if exists, if exists, solve the colision (maybe in a while loop until guarantee its unique).
I can't imagine so many file per micro-second.
精彩评论