Jump to content

Php Search And Display Results


BenardZMEDIA

Recommended Posts

i have this sample script i would like to add to my existing php page to search a directory and display the results with a download link. here is the script any ideas where am going wrong?

 

 

<?php
$dir = 'my_directory';
$exclude = array('.','..','.htaccess');
$q = (isset($_GET['q']))? strtolower($_GET['q']) : '';
$res = opendir($dir);
while(false!== ($file = readdir($res))) {
if(strpos(strtolower($file),$q)!== false &&!in_array($file,$exclude)) {
echo "<a href='$dir/$file'>$file</a>";
echo "<br>";
}
}
closedir($res);
?>
<form action="my_phpfile" method="get"><input name="q"
type="text"> <input type="submit"></form>

Link to comment
https://forums.phpfreaks.com/topic/271021-php-search-and-display-results/
Share on other sites

Actually, it is searching for all files whose name contains the character sequence typed by the user. It could be a single character, or a file extension, or any part of the filename. It lists each file found as a link.

 

The fact that you posted here indicates you are having some kind of problem with the script. However, you have not stated what the problem is. If you tell us what it does that it should NOT do, or what it does NOT do that it SHOULD do; we may be able to provide some help.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.