Can PHP read mp3 information?
Moderator: General Moderators
Can PHP read mp3 information?
I'd like to get the name and artist out of a mp3 that is in the script's directory.
Quicker than you, I found it 2 minutes after that other post I made. I got it to work, but now I am wondering how I can use it for another purpose, and so far it hasn't worked. I am wanting to get the files of a directory, and for all the mp3's, if the artist is a certain artist then to display a list of those songs. Here is the code I have so far, it shows a blank page:
And, I have several songs for that artist, and they are in the same directory.
Code: Select all
<?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);
?>