To store uploaded files by users on remote server inside disk folder I change the name of file to
$filename = '/tmp/foo.txt';
$newName = sha1_file($filename); // 40 characters
//or I can do
$newName = uniqid($filename) // 13 characters
Which is a more robust method for new name that is not likely to fail ??
Thanks.
A better solution is to use
tmpfile()ortempnam(). Either one is guaranteed to create an unused file that won’t collide and can’t be “intercepted” by rogue processes changing permissions on you.tmpfile()automatically deletes the file when it’s closed, whereastempnam()keeps it aroundhttp://www.php.net/manual/en/function.tmpfile.php
http://www.php.net/manual/en/function.tempnam.php