Click to See Complete Forum and Search --> : Search for files?
Pixel-Artist
11-23-2006, 10:23 PM
How would I make a script that searches for files in a directory with some put of what I inputed in it?
Lets pretend I already collected search information into $inputed
I would really appreciate it.
pcthug
11-24-2006, 01:06 AM
Totally Untested, though this may get you started:
$dir = dirname(__FILE__);
$inputed = NULL;
$files = $results = array();
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && is_file($file)) {
$files[] = $file;
}
}
closedir($handle);
}
foreach($files as $key)
if(strpos($key, $inputed) === true)
$results[] = $dir . DIRECTORY_SEPARATOR . $key;
Results returned via the $results array as entire filepaths.
legendx
11-24-2006, 06:17 AM
glob() is the easiest way to search through a directory.
http://us2.php.net/manual/en/function.glob.php
quick and painless