I have developed an API integration, It contains multiple image/file uploads. There are name conflicts if multiple users uploads file with the same name.
I\'ve plan
I guess that it is best to have a function that tries creating random folders (and verifying if it is successful) until it succeeds.
This one has no race conditions nor is it depending on faith in uniqid() providing a name that has not already been used as a name in the tempdir.
function tempdir() {
$name = uniqid();
$dir = sys_get_temp_dir() . '/' . $name;
if(!file_exists($dir)) {
if(mkdir($dir) === true) {
return $dir;
}
}
return tempdir();
}