- pathinfo: documentation ( source)
- file_exists: documentation ( source)
<?php
function makeRandomPath($dir, $ext) {
do {
$path = $dir."/".genRandomString().".".$ext;
} while(file_exists($path));
return $path;
}
echo makeRandomPath();
function makeRandomPathFromFilename($dir, $fn) {
$ext = pathinfo($fn, PATHINFO_EXTENSION);
return makeRandomPath($dir, $ext);
}
echo makeRandomPathFromFilename();