Jump to content

Search for mp3s


davehardyuk

Recommended Posts

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!)

[code]<?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>";
}
}
}
}
?>[/code]
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
Link to comment
https://forums.phpfreaks.com/topic/4444-search-for-mp3s/
Share on other sites

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.
[code]<?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);
}
?>[/code]

Start with:
[code]<?php
$path="path/to/your/dir";
read_dir($path);[/code]
?>[/quote]
Link to comment
https://forums.phpfreaks.com/topic/4444-search-for-mp3s/#findComment-15436
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.