Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
$verzeichnis = opendir("/mp3/");
$i = 0;
while($datei = readdir($verzeichnis)) { //Die Datein werden zeile für zeile in die variable $datei geschrieben
if (!is_dir($datei)){ //Verzeichnisse sollen ja nicht dargestellt werden
$daten[$i] = "$datei";
$i++;
}
}
closedir($verzeichnis);
function mp3info($file)
{
$fp = fopen($file, "rb");
if (!$fp) return 0;
// Try to find ID3v1.x
fseek($fp, filesize($file)-128);
$id3v1 = fread($fp, 128);
if (substr($id3v1, 0, 3) == "TAG")
{ // Yay!
$mp3[title] = trim(substr($id3v1, 3, 30));
$mp3[artist] = trim(substr($id3v1, 33, 30));
$mp3[album] = trim(substr($id3v1, 63, 30));
$mp3[year] = trim(substr($id3v1, 93, 4));
if (substr($id3v1, 125, 1) == "\0" && substr($id3v1, 126, 1) != "\0")
{ // we got a ID3v1.1 here
$mp3[comment] = trim(substr($id3v1, 97, 29));
$mp3[track] = ord(substr($id3v1, 126, 1));
}
else
{ // old ID3v1
$mp3[comment] = trim(substr($id3v1, 97, 30));
}
$mp3[genre] = ord(substr($id3v1, 127, 1));
}
else $mp3 = 0;
fclose($fp);
return $mp3;
}
<?
include("functions.inc.php"); // angenommen die mp3info() steht in dieser Datei
$verzeichnis = "./mp3/";
$dir = opendir($verzeichnis);
while($datei = readdir($dir)) {
if (is_file($verzeichnis.$datei) && (substr($datei, -3, 3) == "mp3"))
{
$info = mp3info($verzeichnis.$datei);
if ($info) echo "Datei: $datei<br>Artist: $info[artist]<br>Title: $info[title]<br>Album: $info[album]<br><br>";
}
}
?>
<?
/*
This file was written by Anders Bruun Olsen (anders@gerf.dk)
It is all released under the GNU GPL license and therefore free
for everybody to use.
I hope that someone will find it useful and perhaps clean it up
and make it a bit smoother..
The newest version of this file can be found at:
http://www.elffan.com/id3v2
For those in doubt, it is used by giving a filename (preferebly
with a full path) of an MP3 file containing an ID3v2 tag to
extract_id3v2().
An array is then returned containing all the frames in the tag.
History:
02-03-2001 - Fixed a problem where the code would timeout on larger
files. This means that at the moment only files with
the ID3v2 tag at the very beginning of the file can be
read.
01-03-2001 - First release.
*/
function rem_synchsafe ($tal)
{
$tal = hexdec(bin2hex($tal));
$tal1 = floor($tal/256) * 128 + ($tal%256);
$tal2 = floor($tal1/32768) * 16384 + ($tal1%32768);
$sluttal = floor($tal2/4194304) * 2097152 + ($tal2%4194304);
return $sluttal;
};
function get_flags ($fp)
{
// This function reads the flag bit and puts out something useful...
$flags = hexdec(bin2hex(fgetc($fp)));
if (($flags - 128) >= 0) {
// flag a is set (Unsynchronisation)
$flags = $flags - 128;
$flaglist .= "a,";
}
if (($flags - 64) >= 0) {
// flag b is set (Extended Header)
$flags = $flags - 64;
$flaglist .= "b,";
}
if (($flags - 32) >= 0) {
// flag c is set (Experimental indicator)
$flags = $flags - 32;
$flaglist .= "c,";
}
if (($flags - 16) >= 0) {
// flag d is set (Footer present)
$flags = $flags - 16;
$flaglist .= "d,";
}
if (($flags - 8) >= 0) {
// flag e is set (Unused in v2.4.0)
$flags = $flags - 8;
$flaglist .= "e,";
}
if (($flags - 4) >= 0) {
// flag f is set (Unused in v2.4.0)
$flags = $flags - 4;
$flaglist .= "f,";
}
if (($flags - 2) >= 0) {
// flag g is set (Unused in v2.4.0)
$flags = $flags - 2;
$flaglist .= "g,";
}
if (($flags - 1) >= 0) {
// flag h is set (Unused in v2.4.0)
$flags = $flags - 1;
$flaglist .= "h,";
}
if (strlen($flaglist) > 0)
{
$flaglist = substr($flaglist,0,strlen($flaglist)-1);
}
return $flaglist;
};
function get_id3pos ($filename)
{
// This function will return the position of the ID3v2 tag if found
$fp = fopen($filename,"r");
while(!feof($fp)){
$char = fgetc($fp);
if($char == "I") {
$char = fgetc($fp);
if ($char == "D") {
$char = fgetc($fp);
if ($char == "3") {
$id3pos = ftell($fp);
}
}
}
}
fclose($fp);
if (!$id3pos) {
return false;
} else {
return $id3pos;
}
};
function goto_id3pos ($filename,$id3pos)
{
// This function will open the file, go to the ID3v2 tag position and return the filepointer
$fp = fopen($filename,"r");
if (fseek($fp,$id3pos) != 0) {
die ("Could not go to ID3 tag\n");
}
return $fp;
};
function get_id3_version ($fp)
{
// This function gets the ID3v2 version from the file open at the filepointer and returns it
$ver1 = hexdec(bin2hex(fgetc($fp)));
$ver2 = hexdec(bin2hex(fgetc($fp)));
$version = "ID3v2." . $ver1 . "." . $ver2;
return $version;
};
function get_tagsize ($fp)
{
// This function gets the tagsize converts it from a synchsafe int to a normal int and returns it
for ($i = 0; $i < 4; $i++) {
$tagsize .= fgetc($fp);
}
$tagsize = rem_synchsafe($tagsize);
return $tagsize;
};
function extract_id3v2($filename)
{
// Find the position of the ID3v2 tag
//if (!$id3pos = get_id3pos($filename)) {
//die("No ID3v2 tag found in $filename\n");
//};
// go to id3v2 tag in file
//$fp = goto_id3pos($filename,$id3pos);
$fp = goto_id3pos($filename,3);
// Get the version
$id3ver = get_id3_version($fp);
$id3flags = get_flags($fp);
$tagsize = get_tagsize($fp);
$tagsize_left = $tagsize;
while ($tagsize_left > 1) {
unset($frameID);
unset($framesize);
unset($frame);
for ($i = 0; $i < 4; $i++) {
$frameID .= fgetc($fp);
}
for ($i = 0; $i < 4; $i++) {
$framesize .= fgetc($fp);
}
$framesize = rem_synchsafe($framesize);
if ($framesize >= 1)
{
$tagsize_left = $tagsize_left - ($framesize + 10);
$flag1 = get_flags($fp);
$flag2 = get_flags($fp);
$encoding = hexdec(bin2hex(fgetc($fp)));
if ($encoding <= 3) {
// This is the encoding bit
for ($i = 0; $i < ($framesize - 1); $i++) {
$frame .= fgetc($fp);
}
} else {
// This was not an encoding bit, it is part of the frame content
$frame = $encoding;
for ($i = 0; $i < $framesize; $i++) {
$frame .= fgetc($fp);
}
}
}
else
{
$frameID = "Padding";
$tagsize_left = 0;
}
if ($frameID == "SYLT" OR $frameID == "USLT" OR $frameID == "USER" OR $frameID == "COMM")
{
$frame = substr($frame,3,strlen($frame));
}
$framearray["$frameID"] = $frame;
};
fclose($fp);
return $framearray;
};
?>
<?php
function getID3v2Tags($file,$blnAllFrames=0){
if(is_file($file) and eregi(".mp3$",$file)){
$arrTag[_file]=$file;
$fp=fopen($file,"rb");
if($fp){
$id3v2=fread($fp,3);
if($id3v2=="ID3"){// a ID3v2 tag always starts with 'ID3'
$arrTag[_ID3v2]=1;
$arrTag[_version]=ord(fread($fp,1)).".".ord(fread($fp,1));// = version.revision
fseek($fp,6);// skip 1 'flag' byte, because i don't need it :)
unset($tagSize);
for($i=0;$i<4;$i++){
$tagSize=$tagSize.base_convert(ord(fread($fp,1)),10,16);
}
$tagSize=hexdec($tagSize);
if($tagSize>filesize($file)){
$arrTag[_error]=4;// = tag is bigger than file
}
fseek($fp,10);
while(ereg("^[A-Z][A-Z0-9]{3}$",$frameName=fread($fp,4))){
unset($frameSize);
for($i=0;$i<4;$i++){
$frameSize=$frameSize.base_convert(ord(fread($fp,1)),10,16);
}
$frameSize=hexdec($frameSize);
if($frameSize>$tagSize){
$arrTag[_error]=5;// = frame is bigger than tag
break;
}
fseek($fp,ftell($fp)+2);// skip 2 'flag' bytes, because i don't need them :)
if($frameSize<1){
$arrTag[_error]=6;// = frame size is smaller then 1
break;
}
if($blnAllFrames==0){
if(!ereg("^T",$frameName)){// = not a text frame, they always starts with 'T'
unset($arrTag[$frameName]);
fseek($fp,ftell($fp)+$frameSize);// go to next frame
continue;// read next frame
}
}
$frameContent=fread($fp,$frameSize);
if(!$arrTag[$frameName]){
$arrTag[$frameName]=trim($frameContent);// the frame content (always?) starts with 0, so it's better to remove it
}
else{// if there is more than one frame with the same name
$arrTag[$frameName]=$arrTag[$frameName]."~".trim($frameContent);
}
}// while(ereg("^[A-Z0-9]{4}$",fread($fp,4)))
}// if($id3v2=="ID3")
else{
$arrTag[_ID3v2]=0;// = no ID3v2 tag found
$arrTag[_error]=3;// = no ID3v2 tag found
}
}// if($fp)
else{
$arrTag[_error]=2;// can't open file
}
fclose($fp);
}// if(is_file($file) and eregi(".mp3$",$file)){
else{
$arrTag[_error]=1;// = file doesn't exists or isn't a mp3
}
return $arrTag;
}
?>
getID3v2Tags("test.mp3",0);
Matthias Reitinger hat gesagt.:Hallöle Fungo,
weil ich das interessant fand, hab ich mich mal kurz hingesetzt und eine Funktion geschrieben, die den ID3v1 od. ID3v1.1 Tag einer MP3 ausliest und die Informationen in einem Array zurückgibt. ID3v2.x wird nicht unterstützt.
PHP:function mp3info($file) { $fp = fopen($file, "rb"); if (!$fp) return 0; // Try to find ID3v1.x fseek($fp, filesize($file)-128); $id3v1 = fread($fp, 128); if (substr($id3v1, 0, 3) == "TAG") { // Yay! $mp3[title] = trim(substr($id3v1, 3, 30)); $mp3[artist] = trim(substr($id3v1, 33, 30)); $mp3[album] = trim(substr($id3v1, 63, 30)); $mp3[year] = trim(substr($id3v1, 93, 4)); if (substr($id3v1, 125, 1) == "\0" && substr($id3v1, 126, 1) != "\0") { // we got a ID3v1.1 here $mp3[comment] = trim(substr($id3v1, 97, 29)); $mp3[track] = ord(substr($id3v1, 126, 1)); } else { // old ID3v1 $mp3[comment] = trim(substr($id3v1, 97, 30)); } $mp3[genre] = ord(substr($id3v1, 127, 1)); } else $mp3 = 0; fclose($fp); return $mp3; }
Anwendungsbeispiel:
PHP:<? include("functions.inc.php"); // angenommen die mp3info() steht in dieser Datei $verzeichnis = "./mp3/"; $dir = opendir($verzeichnis); while($datei = readdir($dir)) { if (is_file($verzeichnis.$datei) && (substr($datei, -3, 3) == "mp3")) { $info = mp3info($verzeichnis.$datei); if ($info) echo "Datei: $datei<br>Artist: $info[artist]<br>Title: $info[title]<br>Album: $info[album]<br><br>"; } } ?>
Hope that helps
reima
Notice: Use of undefined constant title - assumed 'title' in c:\programme\apache\...\index.php on line 12