I am using the Amazon S3 API to upload files and I am changing the name of the file each time I upload.
So for example:
Dog.png > 3Sf5f.png
Now I got
i am using this in my websites (and works fine for years):
$file = 'yourOriginalfile.png';
//get the file extension
$fileExt = substr(strrchr($file, '.'), 1);
//create a random name and add the original extension
$fileUniqueName = md5(uniqid(mktime())) . '.' . $fileExt;
rename($file,$fileUniqueName);
your function generates too short filenames (5 characters), this way creates longer filenames, avoiding to collide the file names.
example output: aff5a25e84311485d4eedea7e5f24a4f.png