PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I am wanting to list mp3's in a directory, but ONLY if the artist is System of a Down, it reads the files' id3 tags, but I obviously messed up somewhere., since It displays a blank page.
<?php
$path = "/homepages/21/d155481990/htdocs/server";
$dir_handle = @opendir($path) or die("Unable to open $path");
while ($file = readdir($dir_handle))
{
if($file!="." && $file!=".." && $file!="songlist.php" && $file!="song.php" && $file!="music.html" && $file!="songdevlist.php" && $file!=null)
$mp3 = $file; //MP3 file to be read
$filesize = filesize($mp3);
$file = fopen($mp3, "r");
fseek($file, -128, SEEK_END);
$tag = fread($file, 3);
if($tag == "TAG")
{
$data["artist"] = trim(fread($file, 30));
}
else
die("");
fclose($file);
strtolower($mp3);
while(list($key, $value) = each($data))
{
if ($data["artist"] == 'system of a down')
{ print("$key: $value<br>\r\n"); }
}
}
//closing the directory
closedir($dir_handle);
?>
And, I have several songs for that artist, and they are in the same directory and I am sure the songs have that artist in their id3 tags. I have a different script that will display the id3 tags of a specific file to verify it.
Do these files use ID3v1 or ID3v2 or both? Btw.. you're missing some braces. They shouldn't cause a blank page (which you should check your errors logs for) but would mess up some of the logic you are trying to accomplish.
I fixed the possible error, and I also put an error message in the die function, and now it always displays the error message. So, it's not reading the directory's files, at least not correctly.
feyd wrote:Do these files use ID3v1 or ID3v2 or both?
They use possibly both, I haven't checked, but I'm not trying to get any extra ID tags in the files, just the artist one, which should be in it whether v1 or v2.
Well, that code could list each of the files individually in its original form, but I tried to adapt it to its current forum to go through each mp3. If you'd like the original code (which isn't much different), just ask. I also implemented a directory listing script into that also, trying to get the combo to do what I wanted.