BenardZMEDIA Posted November 22, 2012 Share Posted November 22, 2012 (edited) 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> Edited November 22, 2012 by BenardZMEDIA Quote Link to comment https://forums.phpfreaks.com/topic/271021-php-search-and-display-results/ Share on other sites More sharing options...
DavidAM Posted November 25, 2012 Share Posted November 25, 2012 ...any ideas where am going wrong? By not telling us what is does that it should not do; or what it does not do that it should do. Quote Link to comment https://forums.phpfreaks.com/topic/271021-php-search-and-display-results/#findComment-1394899 Share on other sites More sharing options...
BenardZMEDIA Posted November 29, 2012 Author Share Posted November 29, 2012 this piece of code is searching for a file name the user has keyed in and display it as a link to download. Quote Link to comment https://forums.phpfreaks.com/topic/271021-php-search-and-display-results/#findComment-1396129 Share on other sites More sharing options...
DavidAM Posted November 29, 2012 Share Posted November 29, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/271021-php-search-and-display-results/#findComment-1396174 Share on other sites More sharing options...
Christian F. Posted December 1, 2012 Share Posted December 1, 2012 BenardZMEDIA: I recommend that you read this article. Quote Link to comment https://forums.phpfreaks.com/topic/271021-php-search-and-display-results/#findComment-1396621 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.