I am trying to recursively read all the files in a folder and its sub folder. Upon reading these files I want to calculate their checksum and store them in an array.
On modifying the code previously written by Shef and mentioned on stack overflow, i have the following -
function listFolderFiles($dir){
global $hash_array;
$folder = scandir($dir);
foreach($folder as $file){
if($file != '.' && $file != '..' && $file != '.DS_Store'){
if(is_dir($dir.'/'.$file)) {
echo "Here is a folder $file<br>";
listFolderFiles($dir.'/'.$file);
} else {
echo "SHA checksum of $file - ".sha1_file($file)."<br>";
$hash_array[] = $file;
}
}
}
}
However, the output of this is a checksum of only the last file the script reads. Can anyone spot a problem here?