I have a server with a lot of files inside various folders, sub-folders, and sub-sub-folders.
I'm trying to make a search.php page that would be used to search the whole server for a specific file. If the file is found, then return the location path to display a download link.
Here's what i have so far:
$root = $_SERVER['DOCUMENT_ROOT'];
$search = "test.zip";
$found_files = glob("$root/*/test.zip");
$downloadlink = str_replace("$root/", "", $found_files[0]);
if (!empty($downloadlink)) {
echo "<a href=\"http://www.example.com/$downloadlink\">$search</a>";
}
The script is working perfectly if the file is inside the root of my domain name... Now i'm trying to find a way to make it also scan sub-folders and sub-sub-folders but i'm stuck here.
file_exists()
function. php.net/manual/en/function.file-exists.php (or a mix of). – Giverinmessi fan
put up? Seems promising. I'm dabbling with it now, and it's showing me all files in starting folder and sub-folders, but not working the way you want it to. Plus, I've got both eyes in the same socket right; needing some sleep, very soon. – Giverin