Forum Moderators: coopster
Currently the script works great when the correct name is entered but is blank when incorrect name is entered.
Here's the code...
<?php
$dir = "test";
$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 "<b><u>Search Results</u></b>";
echo "<br><br>";
echo "<a href='$file' target='_blank'>$file</a>";
echo "<br>";
echo "<br>";
echo "<br>";
echo "<br>";
echo "<a href='./'>Go Back to Search</a>";
}
}
closedir($res);
?>
<?php
$dir = "test";
$exclude = array('.','..','.htaccess');
$q = (isset($_GET['q']))? strtolower($_GET['q']) : '';
$res = opendir($dir);
$foundfile = false;
while(false!== ($file = readdir($res))) {
if(strpos(strtolower($file),$q)!== false &&!in_array($file,$exclude)) {
echo "<b><u>Search Results</u></b>";
echo "<br><br>";
echo "<a href='$file' target='_blank'>$file</a>";
echo "<br>";
echo "<br>";
echo "<br>";
echo "<br>";
echo "<a href='./'>Go Back to Search</a>";
$foundfile = true;
}
}
closedir($res);
if (!$foundfile) {
echo 'you blew it!';
}
?>
should work