Jump to content


Photo

Search for mp3s


  • Please log in to reply
2 replies to this topic

#1 davehardyuk

davehardyuk
  • New Members
  • Pip
  • Newbie
  • 7 posts
  • LocationPlymouth, UK

Posted 08 March 2006 - 03:47 PM

Hi Guys,

Currently i can get a page to scan files in a folder, if they're mp3's list them, otherwise open up the subfolder and display those mp3s that include the text as links, but can't get it to go into the next subfolder! my code is as follows: (apologies for the bad formatting!)

<?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='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/media/$file&download=yes' target='player'>$file</a></strong></td></tr></table>"; 
}
if ($extension  !=  "mp3") {

$dir=opendir("media/$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){
$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='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/media/$file&download=yes' target='player'>$file</a></strong></td></tr></table>"; 
}
}
}
}
?>
I'm wanting to create a search page that will search the folder "media" and all of it's subfolders for mp3 files and then list them as links to playmedia.php?fileid= --mp3 url here --

I'm getting the search text and putting it into a variable called $searchstring

Any help would be greatly appreciated!

Thanks in advance!

Dave

#2 davehardyuk

davehardyuk
  • New Members
  • Pip
  • Newbie
  • 7 posts
  • LocationPlymouth, UK

Posted 08 March 2006 - 04:20 PM

Actually I think I should be ok if i just knew the code to open subdirectories within the folder "media".

Sorry my first confusing post!

Thanks,

Dave

#3 Ferenc

Ferenc
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts

Posted 08 March 2006 - 04:42 PM

I found this at php.net...


[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
*updated version

Here is my recursive read_dir function. It sorts directories and files alphabetically.
<?php
function read_dir($dir) {
   $path = opendir($dir);
   while (false !== ($file = readdir($path))) {
       if($file!="." && $file!="..") {
           if(is_file($dir."/".$file))
               $files[]=$file;
           else
               $dirs[]=$dir."/".$file;           
       }
   }
   if($dirs) {
       natcasesort($dirs);
       foreach($dirs as $dir) {
           echo $dir;
           read_dir($dir);
       }
   }
   if($files) {
       natcasesort($files);
       foreach ($files as $file)
           echo $file
   }
   closedir($path);
}
?>

Start with:
<?php
$path="path/to/your/dir";
read_dir($path);
?>[/quote]
Everything you want to know is here.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users