Display ID3 data in webpage?

Soldato
Joined
14 Dec 2005
Posts
12,488
Location
Bath
On a website I’m making there’s going to be a page that’s includes downloads of mp3’s that I’m hosting (don’t worry, these are talks that I’ve got the copyright to!) and will need to have the relevant artist/title/etc details displayed along with the download link.

Is there a way of getting the webpage to read the ID3 tags from the mp3 files in the directory and then display the ID3 data along with the download link?

Is this something that can be done through PHP of some sort?

TY
Ed
 
You can do it through PHP - google "PHP READ ID3".

Note that there are a couple of different ID3 versions which you will need to take account of. I'm also not sure of the overhead of reading such files. It may slow your page down quite significantly. You may want to consider using some sort of cache so you don't re-open files every time your page is opened.
 
Yey it's possible, thanks :D


Although it looks far more complicated than anything I've ever used in PHP before :(

There wouldn't happen to be a Layman's easy guide anywhere would there?
 
Last edited:
I've had a fiddle around with getID3() and me likes :)

The way I like it to output is the demo.simple.php template:
Code:
<?php
/////////////////////////////////////////////////////////////////
/// getID3() by James Heinrich <[email protected]>               //
//  available at http://getid3.sourceforge.net                 //
//            or http://www.getid3.org                         //
/////////////////////////////////////////////////////////////////
//                                                             //
// /demo/demo.simple.php - part of getID3()                    //
// Sample script for scanning a single directory and           //
// displaying a few pieces of information for each file        //
// See readme.txt for more details                             //
//                                                            ///
/////////////////////////////////////////////////////////////////

echo '<HTML><HEAD>';
echo '<TITLE>getID3() - /demo/demo.simple.php (sample script)</TITLE>';
echo '<STYLE>BODY,TD,TH { font-family: sans-serif; font-size: 9pt; }</STYLE>';
echo '</HEAD><BODY>';


// include getID3() library (can be in a different directory if full path is specified)
require_once('../getid3/getid3.php');

// Initialize getID3 engine
$getID3 = new getID3;

$DirectoryToScan = '/change/to/directory/you/want/to/scan'; // change to whatever directory you want to scan
$dir = opendir($DirectoryToScan);
echo '<TABLE BORDER="1" CELLSPACING="0" CELLPADDING="3">';
echo '<TR><TH>Filename</TH><TH>Artist</TH><TH>Title</TH><TH>Bitrate</TH><TH>Playtime</TH></TR>';
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 '<TR>';
		echo '<TD>'.$ThisFileInfo['filenamepath'].'</TD>';
		echo '<TD>'.(!empty($ThisFileInfo['comments_html']['artist']) ? implode('<BR>', $ThisFileInfo['comments_html']['artist']) : '&nbsp;').'</TD>';
		echo '<TD>'.(!empty($ThisFileInfo['comments_html']['title'])  ? implode('<BR>', $ThisFileInfo['comments_html']['title'])  : '&nbsp;').'</TD>';
		echo '<TD ALIGN="RIGHT">'.(!empty($ThisFileInfo['audio']['bitrate'])        ? round($ThisFileInfo['audio']['bitrate'] / 1000).' kbps'   : '&nbsp;').'</TD>';
		echo '<TD ALIGN="RIGHT">'.(!empty($ThisFileInfo['playtime_string'])         ? $ThisFileInfo['playtime_string']                          : '&nbsp;').'</TD>';
		echo '</TR>';
	}
}

?>
</BODY>
</HTML>

and I've fiddled around with it to display different parts of the ID3 data etc and that all works fine :cool:

The bit I can't get is how to display a link to the mp3 files for the user to download them :confused:


EDIT: Don't worry, I did it :D
FYI I've used:
Code:
echo '<TD>'."Download " . "<a href='songs/$ThisFileInfo[filename]'>$ThisFileInfo[filename]</a>". '</TD>';
 
Last edited:
Back
Top Bottom