Jump to content

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>

Edited by BenardZMEDIA
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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.