brodwilkinson Posted May 9, 2009 Share Posted May 9, 2009 ohk so after 2 days of coding i just cant get it to work, im trying to make a search which displays files in a directory with a filter. eg: you search " gun ", the php looks for all file names with " gun " in it. also the results can only show .ipa files and in a specific directory and if possible can all the coding be on one .php sheet. i'm assuming this must be quite simple. Link to comment https://forums.phpfreaks.com/topic/157463-solved-php-file-search/ Share on other sites More sharing options...
Mark Baker Posted May 9, 2009 Share Posted May 9, 2009 Without some sample code, it's difficult to know where you're going wrong. are you using the glob() function? Link to comment https://forums.phpfreaks.com/topic/157463-solved-php-file-search/#findComment-830166 Share on other sites More sharing options...
brodwilkinson Posted May 9, 2009 Author Share Posted May 9, 2009 Without some sample code, it's difficult to know where you're going wrong. are you using the glob() function? to be honest, its from php scripts i found on the internet.. do you have any ideas of what i need to do to make the search? Link to comment https://forums.phpfreaks.com/topic/157463-solved-php-file-search/#findComment-830168 Share on other sites More sharing options...
Mark Baker Posted May 9, 2009 Share Posted May 9, 2009 to be honest, its from php scripts i found on the internet.. do you have any ideas of what i need to do to make the search? Start by taking a look at the appropriate function in the php manual Link to comment https://forums.phpfreaks.com/topic/157463-solved-php-file-search/#findComment-830170 Share on other sites More sharing options...
brodwilkinson Posted May 9, 2009 Author Share Posted May 9, 2009 thanks, its told me quite abit you cant just explain. what about something that searches the words in a script eg: i have a index.php file which displays whats in the directory its located in: http://teambrod.110mb.com/upload/ now how about i have a search at the top, could i make it so it finds all the matches to: "app 01.ipa""app 02" Link to comment https://forums.phpfreaks.com/topic/157463-solved-php-file-search/#findComment-830183 Share on other sites More sharing options...
thebadbad Posted May 9, 2009 Share Posted May 9, 2009 Since you haven't shown any code, I can only guess. But if you're using glob() to return an array with the files, you can search them like this (had the script lying around anyway): <?php if ($_GET['name'] != '') { $files = glob('directory/to/your/files/*.ipa'); $results = array(); foreach ($files as $file) { if (strpos(basename($file), $_GET['name']) !== false) { $results[] = $file; } } if (count($results) > 0) { echo 'The following files matched the search <em>' . htmlentities($_GET['name']) . "</em>:<br /><br />\n"; foreach ($results as $file) { echo '<a href="' . $file . '">' . basename($file) . '</a><br />' . "\n"; } } else { echo 'No files matched the search <em>' . htmlentities($_GET['name']) . "</em>.<br />\n"; } } else { echo 'Search the files:<br />'; } ?> <br /> <form action="index.php" method="get"> <input type="text" name="name" /> <input type="submit" /> </form> Just remember to change directory/to/your/files/ and index.php to your actual directory and script. And if you want to make the search case-insensitive, use stripos() instead of strpos(). Link to comment https://forums.phpfreaks.com/topic/157463-solved-php-file-search/#findComment-830186 Share on other sites More sharing options...
brodwilkinson Posted May 9, 2009 Author Share Posted May 9, 2009 Since you haven't shown any code, I can only guess. But if you're using glob() to return an array with the files, you can search them like this (had the script lying around anyway): <?php if ($_GET['name'] != '') { $files = glob('directory/to/your/files/*.ipa'); $results = array(); foreach ($files as $file) { if (strpos(basename($file), $_GET['name']) !== false) { $results[] = $file; } } if (count($results) > 0) { echo 'The following files matched the search <em>' . htmlentities($_GET['name']) . "</em>:<br /><br />\n"; foreach ($results as $file) { echo '<a href="' . $file . '">' . basename($file) . '</a><br />' . "\n"; } } else { echo 'No files matched the search <em>' . htmlentities($_GET['name']) . "</em>.<br />\n"; } } else { echo 'Search the files:<br />'; } ?> <br /> <form action="index.php" method="get"> <input type="text" name="name" /> <input type="submit" /> </form> Just remember to change directory/to/your/files/ and index.php to your actual directory and script. And if you want to make the search case-insensitive, use stripos() instead of strpos(). yeah mate, thats very very close to perfect. i tweaked it a little and wahlah all good, you want any credits on the site or script?(i basically did copy and paste the script, only minor changes) Link to comment https://forums.phpfreaks.com/topic/157463-solved-php-file-search/#findComment-830190 Share on other sites More sharing options...
thebadbad Posted May 9, 2009 Share Posted May 9, 2009 No, that's okay. Link to comment https://forums.phpfreaks.com/topic/157463-solved-php-file-search/#findComment-830202 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.