PHP List mp3’s in Directory & Read Tags
This will search your $directory for mp3 files, grab two tags from the mp3 (more can be added to grab).
function list_all_mp3 () { $directory = 'public/downloads/audio/'; $results = array(); $handler = opendir($directory); while ($file = readdir($handler)) { if ($file != '.' && $file != '..') { $mp3 = $file; $filesize = filesize($directory . $mp3); $fh = fopen($directory . $mp3, "r"); fseek($fh, -128, SEEK_END); $tag = fread($fh, 3); if($tag == "TAG") { $title = trim(fread($fh, 30)); $speaker = trim(fread($fh, 30)); } else die("MP3 file does not have any ID3 tag"); fclose($fh); echo "$directory$mp3 - $title \n"; echo "Speaker: $speaker \n"; } } closedir($handler); }
