$path = './fzlhead/';
function get_filetree_scandir($path){
$result = array();
$temp = array();
if (!is_dir ($path)||!is_readable($path)) return null; //Check directory validity
$allfiles = scandir($path); //Get all files and folders in the directory
foreach ($allfiles as $filename) { //Traverse the files and folders in the directory
if (in_array($filename,array('.','..'))) continue; //Ignore. and..
$fullname = $path.'/'.$filename; //Get the full file path
if (is_dir($fullname)) { //If it is a directory, continue the recursion
$result[$filename] = get_filetree_scandir($fullname); //Recursion starts
}
else {
$temp[] = $filename; //If it is a file, store it in the array
$uniqid = uniqid('apoo_');
$ext = pathinfo( $filename, PATHINFO_EXTENSION);
rename($fullname,$path.'/'.$uniqid.'.'.$ext);
}
}
foreach ($temp as $tmp) { // Store the contents of the temporary array into the array that saves the results
$result[] = $tmp; //This allows the folder to be arranged in the front and the file in the back
}
return $result;
}
print_r( get_filetree_scandir($path));
?>