Find files inside starting with a specific string using php

Last updated on May 8th, 2016 at 12:47 am

Click to rate this tutorial!
[Total: 2 Average: 4.5]

Find files inside starting with a specific string using php

.This script will 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);

Click to rate this tutorial!
[Total: 2 Average: 4.5]

Leave a Reply

Your email address will not be published.