PHP find mp3's in folder and sub folders
Posted: Thu Mar 09, 2006 8:55 am
Hi guys,
I have a folder called "media" of which i want to search (including all subfolders, and subfolders within them) for mp3 files and then list them as hyperlinks to "playmedia.php?fileid=(file URL)"
Thanks alot,
Dave
If it helps, here's my code so far. It searches the folder "media" and subfolders and returns only mp3's, but i can't get it to search media -> subfolder -> subfolder
I have a folder called "media" of which i want to search (including all subfolders, and subfolders within them) for mp3 files and then list them as hyperlinks to "playmedia.php?fileid=(file URL)"
Thanks alot,
Dave
If it helps, here's my code so far. It searches the folder "media" and subfolders and returns only mp3's, but i can't get it to search media -> subfolder -> subfolder
Code: Select all
<?php
$searchstring = $_REQUEST['searchstring'];
if ($searchstring == ""){
print "Please enter some text to search for!";
return;
}
$dir=opendir("media");
$files=array();
while (($file=readdir($dir)) !== false)
{
if ($file != "." and $file != ".." and $file != "index.php" and $file != "fileupload-class.php" and $file != "icon.gif" and $file != "launch.gif" and $file != "download.php" and $file != "index.asp" and $file != "images" and $file != "login_check.asp" and $file != "main.php" and $file != "delete.gif" and $file != "images" and $file != "delete.php" and $file != "spacer.gif" and $file != "ianstanton" and $file != "play_all.m3u" and $file != "play_all_shuffle.m3u")
{
array_push($files, $file);
}
}
closedir($dir);
sort($files);
foreach ($files as $file){
$ext = explode('.', $file);
$extension = $ext[count($ext)-1];
if (($extension == "mp3")&&(eregi("$searchstring", $file))) {
print "<table width='220' border='0'>
<tr><td align='left' valign'top'><a href='http://audiostation/playmedia.php?fileid=http://audiostation/media/$file&download=yes' target='player'><img src='images/music_icon.gif' alt='$file' border='0'></a><td></td><td width='205' style='font-family: Arial, Helvetica, sans-serif; font-size:10px;'><strong><a style='color:001F63;' class='body' href='playmedia.php?fileid=http://audiostation/playmedia.php?fileid=http://audiostation/media/$file&download=yes' target='player'>$file</a></strong></td></tr></table>";
}
if ($extension != "mp3") {
$dir=opendir("media/$file");
$album=$file;
$files=array();
while (($file=readdir($dir)) !== false)
{
if ($file != "." and $file != ".." and $file != "index.php" and $file != "fileupload-class.php" and $file != "icon.gif" and $file != "launch.gif" and $file != "download.php" and $file != "index.asp" and $file != "images" and $file != "login_check.asp" and $file != "main.php" and $file != "delete.gif" and $file != "images" and $file != "delete.php" and $file != "spacer.gif" and $file != "ianstanton" and $file != "play_all.m3u" and $file != "play_all_shuffle.m3u")
{
array_push($files, $file);
}
}
closedir($dir);
sort($files);
foreach ($files as $file){
$get = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'];
$cur_dir = dirname($get);
$DirNow = dirname($get);
$DirUp = dirname($DirNow);
$ext = explode('.', $file);
$extension = $ext[count($ext)-1];
if (($extension == "mp3")&&(eregi("$searchstring", $file))) {
print "<table width='220' border='0'>
<tr><td align='left' valign'top'><a href='http://audiostation/playmedia.php?fileid=media/$album/$file&download=yes' target='player'><img src='images/music_icon.gif' alt='$file' border='0'></a><td></td><td width='205' style='font-family: Arial, Helvetica, sans-serif; font-size:10px;'><strong><a style='color:001F63;' class='body' href='playmedia.php?fileid=media/$album/$file&download=yes' target='player'>$file</a></strong></td></tr></table>";
}
}
}
}
?>