<?php
if ($handle = opendir("music/")) {
$thelist = array();
while (false !== ($file = readdir($handle)))
if (preg_match("/\.doc/i",$file))
{
if ($file != "." && $file != "..")
{
$thelist[] = '<a href="music/'.$file.'">'.$file.'</a><br />';
}
}
closedir($handle);
}
sort($thelist);
$thelist = implode("\n",$thelist);
?>
<?=$thelist?>
<?php // RAY_search_directory.php - NOT CASE SENSITIVE
error_reporting(E_ALL);
echo "<pre>\n";
// IF THE SEARCH ARGUMENT HAS BEEN POSTED
if (!empty($_GET["q"]))
{
// NORMALIZE THE SEARCH STRING
$q = trim(strtoupper($_GET["q"]));
// ACTIVATE THIS TO SEE THE SEARCH ARGUMENT
// var_dump($q);
// GET THE LIST OF FILES IN THIS DIRECTORY
$arr = scandir(getcwd());
// ACTIVATE THIS TO SEE ALL THE FILES
// var_dump($arr);
// ITERATE OVER THE LIST OF FILENAMES FROM THIS DIRECTORY
foreach ($arr as $p => $fn)
{
// REMOVE FILENAMES WITH STRINGS THAT DO NOT MATCH THE SEARCH ARGS
// MAN PAGE: http://us2.php.net/manual/en/function.strpos.php
$poz = strpos($fn, $q);
if ($poz === FALSE) unset($arr[$p]);
}
// SHOW WHAT WE HAVE LEFT IN THE ARRAY - MATCHING THE ARGS
var_dump($arr);
} // END OF PHP, PUT UP THE FORM FOR INPUT VALUES
?>
<form>
ENTER SEARCH STRING
<input name="q" />
<input type="submit" />
</form>
<?php
$search = @$_GET["search"];
if ($handle = opendir("music/")) {
$thelist = array();
while (false !== ($file = readdir($handle)))
if (preg_match("/\.doc/i",$file))
{
if ($file != "." && $file != "..")
{
if $(search =="") {
// Show all results
$thelist[] = '<a href="music/'.$file.'">'.$file.'</a><br />';
} else {
// Show selected results
$pos = strpos(strtolower($file), strtolower($search));
if ($pos === true) {
$thelist[] = '<a href="music/'.$file.'">'.$file.'</a><br />';
}
}
}
}
closedir($handle);
}
sort($thelist);
$thelist = implode("\n",$thelist);
echo $thelist;
?>
<?php
$search = @$_GET["search"];
if ($handle = opendir("music/")) {
$thelist = array();
while (false !== ($file = readdir($handle)))
{
if (preg_match("/\.doc/i",$file))
{
if ($file != "." && $file != "..")
{
if ($search == "") {
// Show all results
$thelist[] = '<a href="music/'.$file.'">'.$file.'</a><br />';
} else {
// Show selected results
$pos = strstr(strtolower($file), strtolower($search));
if ($pos == true) {
$thelist[] = '<a href="music/'.$file.'">'.$file.'</a><br />';
}
}
}
}
}
closedir($handle);
}
sort($thelist);
$thelist = implode("\n",$thelist);
echo $thelist;
?>
I think you want to look at
http://us2.php.net/manual/en/function.readdir.php
This will allow you to read the files and build an array. if you use reg expressions you could search!
I hope this helps