I was able to resolve this by deleting the find_file function. All of this from line 87-115 was replaced:
// Get real file name.
// Remove any path info to avoid hacking by adding relative path, etc.
$fname = basename($_GET['f']);
// Check if the file exists
// Check in subfolders too
function find_file ($dirname, $fname, &$file_path) {
$dir = opendir($dirname);
while ($file = readdir($dir)) {
if (empty($file_path) && $file != '.' && $file != '..') {
if (is_dir($dirname.'/'.$file)) {
find_file($dirname.'/'.$file, $fname, $file_path);
}
else {
if (file_exists($dirname.'/'.$fname)) {
$file_path = $dirname.'/'.$fname;
return;
}
}
}
}
} // find_file
// get full file path (including subfolders)
$file_path = '';
find_file(BASE_DIR, $fname, $file_path);
Replaced the above with the following, and if you are passing directories in the URL, you can now read them and give absolute paths to the file instead of the script trying to just search for the first file with the file name specified:
// Get the name and path of the file and set the exact file path to the file
$fname = basename($_GET['f']);
$fpath = dirname($_GET['f']);
$file_path = "".BASE_DIR."".$fpath."/".$fname."";
There are security issues with this and parent directories can be traversed, so it's recommended to remove unwanted characters from the $file_path like ../ to prevent directory traversal.