Pulling in mp3 library folder

So I have a client who wanted to have mp3’s that the user could listen to and also download. Since I’m very against having to constantly manage a clients content I wanted him to be able to have no problem adding and removing mp3 files. Normally, one might have an xml file that the user can update but that’s to prone to fail on the side of the client. So what to do…

Enter getId3. This is a super handy tool for anyone who would want to retrieve data about mp3 files via php. Granted, php isn’t that fastest and I have yet to test the speed of retrieval on a large scale, but as of now it seems to be a superb way to automatically generate my listing of mp3 files along with the data attributed to them.

Here is my php file I created to give you an idea of what it can do:

require_once('../../../getid3/getid3/getid3.php');

echo "\n\n";

// include getID3() library (can be in a different directory if full path is specified)

// Initialize getID3 engine
$getID3 = new getID3;

$DirectoryToScan = '../mp3'; // change to whatever directory you want to scan
$dir = opendir($DirectoryToScan);

while (($file = readdir($dir)) !== false ) {
$FullFileName = realpath($DirectoryToScan.'/'.$file);
if (is_file($FullFileName)) {
 set_time_limit(30);

 $ThisFileInfo = $getID3->analyze($FullFileName);

 getid3_lib::CopyTagsToComments($ThisFileInfo);

 // output desired information in whatever format you want
 echo "\t\n";
  echo "\t\t\n";
  echo "\t\t\n";
  echo "\t\t\n";

 echo "\t\n";
}
}
echo "\n";

And here is my result














Posted

in

by

Comments

Leave a Reply