filesize()stat因函数无法获取MP3文件的ID3标签而失败
||
它适用于本地文件,但不适用于外部域。这是我的代码(我从http://www.barattalo.it/2010/02/22/reading-mp3-informations-with-php-id3-tags/获得):
<?
function tagReader($file){
$id3v23 = array(\"TIT2\",\"TALB\",\"TPE1\",\"TRCK\",\"TDRC\",\"TLEN\",\"USLT\");
$id3v22 = array(\"TT2\",\"TAL\",\"TP1\",\"TRK\",\"TYE\",\"TLE\",\"ULT\");
$fsize = filesize($file);
$fd = fopen($file,\"r\");
$tag = fread($fd,$fsize);
$tmp = \"\";
fclose($fd);
if (substr($tag,0,3) == \"ID3\") {
$result[\'FileName\'] = $file;
$result[\'TAG\'] = substr($tag,0,3);
$result[\'Version\'] = hexdec(bin2hex(substr($tag,3,1))).\".\".hexdec(bin2hex(substr($tag,4,1)));
}
if($result[\'Version\'] == \"4.0\" || $result[\'Version\'] == \"3.0\"){
for ($i=0;$i<count($id3v23);$i++){
if (strpos($tag,$id3v23[$i].chr(0))!= FALSE){
$pos = strpos($tag, $id3v23[$i].chr(0));
$len = hexdec(bin2hex(substr($tag,($pos+5),3)));
$data = substr($tag, $pos, 10+$len);
for ($a=0;$a<strlen($data);$a++){
$char = substr($data,$a,1);
if($char >= \" \" && $char <= \"~\") $tmp.=$char;
}
if(substr($tmp,0,4) == \"TIT2\") $result[\'Title\'] = substr($tmp,4);
if(substr($tmp,0,4) == \"TALB\") $result[\'Album\'] = substr($tmp,4);
if(substr($tmp,0,4) == \"TPE1\") $result[\'Author\'] = substr($tmp,4);
if(substr($tmp,0,4) == \"TRCK\") $result[\'Track\'] = substr($tmp,4);
if(substr($tmp,0,4) == \"TDRC\") $result[\'Year\'] = substr($tmp,4);
if(substr($tmp,0,4) == \"TLEN\") $result[\'Length\'] = substr($tmp,4);
if(substr($tmp,0,4) == \"USLT\") $result[\'Lyric\'] = substr($tmp,7);
$tmp = \"\";
}
}
}
if($result[\'Version\'] == \"2.0\"){
for ($i=0;$i<count($id3v22);$i++){
if (strpos($tag,$id3v22[$i].chr(0))!= FALSE){
$pos = strpos($tag, $id3v22[$i].chr(0));
$len = hexdec(bin2hex(substr($tag,($pos+3),3)));
$data = substr($tag, $pos, 6+$len);
for ($a=0;$a<strlen($data);$a++){
$char = substr($data,$a,1);
if($char >= \" \" && $char <= \"~\") $tmp.=$char;
}
if(substr($tmp,0,3) == \"TT2\") $result[\'Title\'] = substr($tmp,3);
if(substr($tmp,0,3) == \"TAL\") $result[\'Album\'] = substr($tmp,3);
if(substr($tmp,0,3) == \"TP1\") $result[\'Author\'] = substr($tmp,3);
if(substr($tmp,0,3) == \"TRK\") $result[\'Track\'] = substr($tmp,3);
if(substr($tmp,0,3) == \"TYE\") $result[\'Year\'] = substr($tmp,3);
if(substr($tmp,0,3) == \"TLE\") $result[\'Lenght\'] = substr($tmp,3);
if(substr($tmp,0,3) == \"ULT\") $result[\'Lyric\'] = substr($tmp,6);
$tmp = \"\";
}
}
}
return $result;
}
$song = tagReader(\"file.mp3\");
echo $song[Title];
?>
没有找到相关结果
已邀请:
1 个回复
讼乐
您到底要使用此功能加载什么?您对“它不适用于外部域”是什么意思? 该行仅适用于与此脚本存储在同一目录中的“ 2”。
如果您无法读取本地文件,则应检查该文件的“读取”权限。 为什么fileize()可能不起作用的原因相同。 建议:您应该对字母数字数组索引使用引号...
代替
是的,它可能有效,但仍然不应该这样做。我建议使用单引号来避免在某些特定情况下对变量名的求值(例如数组索引,如
)。