I am writing a PHP script to handle file upload to server. To prevent overwriting when there are files with the same name, the program will rename each uploaded file to the current timestamp.
However, this is not enough. In peak hour, there may be files that are uploaded at the same second. To make sure the uploaded files will have different file names, I am thinking of adding a random number at the end of the timestamp.
Then, I read from the official PHP page on srand()
Note: There is no need to seed the random number generator with srand() or mt_srand() as this is done automatically.
I guess they are using the timestamp for srand()
. If 2 files are uploaded at the same second, so the timestamp for srand()
, will the random result be the same? If yes, is there a way I can make sure the name is not duplicated even if they are uploaded at the same second?