Last updated on January 20th, 2023 at 09:50 am

Script to search for files that starts with a string [Whatever you give] inside the query string.
For instance if the below script is saved inside a file say search_files.php then the script will work if you provide www..com/search_files.php?name=access_log

$dir = "logs";
$dh = opendir($dir);
$dh1 = opendir($dir);
while (($file = readdir($dh)) !== false) {
        $name_prom=$_GET['name'];
$stng = strpos($file,$name_prom);
if($stng === 0)
{
        echo "<a HREF=\"$file\">$file</a><br />\n";
}
}
closedir($dh);

In the above script we are searching a directory named logs and as per the query string the name of the file we are searching is “access_log

Leave a Reply

Your email address will not be published. Required fields are marked *