getID3()是一款從MP3等媒體文件中提取文件信息的php類,既可以提取也能修改文件的標簽信息。它能讀取的文件類型非常多,例如MP3、wav、midi等,這裡就不一一列舉了,詳細版本和可讀取的文件類型可以參考官方網站http://getid3.sourceforge.net/
這裡舉一個獲取mp3文件信息的例子
include "library/getid3/getid3.php"; //引入所需要的類文件
$filename =’myfile.mp3’; //要處理的文件名
$path=’http://localhost/myfolder’; //文件路徑
$radio = realpath($path).DIRECTORY_SEPARATOR.$filename;//獲取文件完整路徑和名稱,注意這裡要使用絕對路徑, 不是http那種絕對路徑,而是服務器的,如果是linux服務器,那麼路徑應該是類似/home/myaccount/public_html /myfolder/myfile.mp3,如果是windows服務器,可能是C:\myfolder\…,注意linux和windows使用的 斜槓不同,這也就是DIRECTORY_SEPARATOR的用處,realpath函數產生的路徑是根據服務器的情況來選擇反斜槓的。
$getID3 = new getID3;//創建一個類的實例
$ThisFileInfo = $getID3->analyze($radio);//分析文件
$time = $ThisFileInfo[‘playtime_seconds’];//獲取mp3的長度信息
下載getid3 >> getid3 已下載 1057 次
下面是我獲取的本地MP3文件信息,打印一下$ThisFileInfo數組,可以根據需要提取需要的信息
Array
(
[GETID3_VERSION] => 1.7.9-20090308
[filesize] => 4577408
[avdataoffset] => 1463
[avdataend] => 4577280
[fileformat] => mp3
=> Array
(
[dataformat] => mp3
[channels] => 2
[sample_rate] => 44100
[bitrate] => 128000
[channelmode] => stereo
[bitrate_mode] => cbr
[lossless] =>
[encoder_options] => CBR128
[compression_ratio] => 0.090702947845805
[streams] => Array
(
[0] => Array
(
[dataformat] => mp3
[channels] => 2
[sample_rate] => 44100
[bitrate] => 128000
[channelmode] => stereo
[bitrate_mode] => cbr
[lossless] =>
[encoder_options] => CBR128
[compression_ratio] => 0.090702947845805
)
)
)
[tags] => Array
(
[id3v1] => Array
(
[title] => Array
(
[0] => 逃亡
)
[artist] => Array
(
[0] => 孫燕姿
)
[album] => Array
(
[0] => 風筝
)
[year] => Array
(
[0] => 2001
)
[comment] => Array
(
[0] => http://51music.dhs.org
)
[track] => Array
(
[0] => 4
)
)
[id3v2] => Array
(
[url_user] => Array
(
[0] => http://www.cy2002.com
)
[comments] => Array
(
[0] => http://51music.dhs.org
)
[year] => Array
(
[0] => 2001
)
[album] => Array
(
[0] => 風筝
)
[artist] => Array
(
[0] => 孫燕姿
)
[title] => Array
(
[0] => 逃亡
)
[track_number] => Array
(
[0] => 4
)
)
)
[encoding] => ISO-8859-1
[filename] => CCD3CDF6_2.mp3
[filepath] => E:/wamp/www/marketing/uploads/radioads
[filenamepath] => E:/wamp/www/marketing/uploads/radioads/CCD3CDF6_2.mp3
[id3v2] => Array
(
[header] => 1
[flags] => Array
(
[unsynch] =>
[exthead] =>
[experim] =>
)
[majorversion] => 3
[minorversion] => 0
[headerlength] => 1463
[tag_offset_start] => 0
[tag_offset_end] => 1463
[encoding] => UTF-8
[comments] => Array
(
[url_user] => Array
(
[0] => http://www.cy2002.com
)
[comments] => Array
(
[0] => http://51music.dhs.org
)
[year] => Array
(
[0] => 2001
)
[album] => Array
(
[0] => 路莽貿脻
)
[artist] => Array
(
[0] => 脣茂脩脿脳脣
)
[title] => Array
(
[0] => 脤脫脥枚
)
[track_number] => Array
(
[0] => 4
)
)
[WXXX] => Array
(
[0] => Array
(
[frame_name] => WXXX
[frame_flags_raw] => 0
[datalength] => 23
[dataoffset] => 10
[framenamelong] => User defined URL link frame
[framenameshort] => url_user
[flags] => Array
(
[TagAlterPreservation] =>
[FileAlterPreservation] =>
[ReadOnly] =>
[compression] =>
[Encryption] =>
[GroupingIdentity] =>
)
[encodingid] => 0
[encoding] => ISO-8859-1
[url] => http://www.cy2002.com
[description] =>
)
)
[COMM] => Array
(
[0] => Array
(
[frame_name] => COMM
[frame_flags_raw] => 0
[data] => http://51music.dhs.org
[datalength] => 27
[dataoffset] => 43
[framenamelong] => Comments
[framenameshort] => comments
[flags] => Array
(
[TagAlterPreservation] =>
[FileAlterPreservation] =>
[ReadOnly] =>
[compression] =>
[Encryption] =>
[GroupingIdentity] =>
)
[encodingid] => 0
[encoding] => ISO-8859-1
[language] => eng
[languagename] => English
[description] =>
)
)
[TYER] => Array
(
[0] => Array
(
[frame_name] => TYER
[frame_flags_raw] => 0
[data] => 2001
[datalength] => 5
[dataoffset] => 80
[framenamelong] => Year
[framenameshort] => year
[flags] => Array
(
[TagAlterPreservation] =>
[FileAlterPreservation] =>
[ReadOnly] =>
[compression] =>
[Encryption] =>
[GroupingIdentity] =>
)
[encodingid] => 0
[encoding] => ISO-8859-1
)
)
[TALB] => Array
(
[0] => Array
(
[frame_name] => TALB
[frame_flags_raw] => 0
[data] => 風筝
[datalength] => 5
[dataoffset] => 95
[framenamelong] => Album/Movie/Show title
[framenameshort] => album
[flags] => Array
(
[TagAlterPreservation] =>
[FileAlterPreservation] =>
[ReadOnly] =>
[compression] =>
[Encryption] =>
[GroupingIdentity] =>
)
[encodingid] => 0
[encoding] => ISO-8859-1
)
)
[TPE1] => Array
(
[0] => Array
(
[frame_name] => TPE1
[frame_flags_raw] => 0
[data] => 孫燕姿
[datalength] => 7
[dataoffset] => 110
[framenamelong] => Lead performer(s)/Soloist(s)
[framenameshort] => artist
[flags] => Array
(
[TagAlterPreservation] =>
[FileAlterPreservation] =>
[ReadOnly] =>
[compression] =>
[Encryption] =>
[GroupingIdentity] =>
)
[encodingid] => 0
[encoding] => ISO-8859-1
)
)
[TIT2] => Array
(
[0] => Array
(
[frame_name] => TIT2
[frame_flags_raw] => 0
[data] => 逃亡
[datalength] => 5
[dataoffset] => 127
[framenamelong] => Title/songname/content description
[framenameshort] => title
[flags] => Array
(
[TagAlterPreservation] =>
[FileAlterPreservation] =>
[ReadOnly] =>
[compression] =>
[Encryption] =>
[GroupingIdentity] =>
)
[encodingid] => 0
[encoding] => ISO-8859-1
)
)
[TRCK] => Array
(
[0] => Array
(
[frame_name] => TRCK
[frame_flags_raw] => 0
[data] => 4
[datalength] => 2
[dataoffset] => 142
[framenamelong] => Track number/Position in set
[framenameshort] => track_number
[flags] => Array
(
[TagAlterPreservation] =>
[FileAlterPreservation] =>
[ReadOnly] =>
[compression] =>
[Encryption] =>
[GroupingIdentity] =>
)
[encodingid] => 0
[encoding] => ISO-8859-1
)
)
[padding] => Array
(
[start] => 154
[length] => 1309
[valid] => 1
)
)
[id3v1] => Array
(
[title] => 逃亡
[artist] => 孫燕姿
[album] => 風筝
[year] => 2001
[comment] => http://51music.dhs.org
[track] => 4
[comments] => Array
(
[title] => Array
(
[0] => 逃亡
)
[artist] => Array
(
[0] => 孫燕姿
)
[album] => Array
(
[0] => 風筝
)
[year] => Array
(
[0] => 2001
)
[comment] => Array
(
[0] => http://51music.dhs.org
)
[track] => Array
(
[0] => 4
)
)
[padding_valid] => 1
[tag_offset_end] => 4577408
[tag_offset_start] => 4577280
[encoding] => ISO-8859-1
)
[mime_type] => audio/mpeg
[mpeg] => Array
(
=> Array
(
[raw] => Array
(
[synch] => 4094
[version] => 3
[layer] => 1
[protection] => 1
[bitrate] => 9
[sample_rate] => 0
[padding] => 1
[private] => 0
[channelmode] => 1
[modeextension] => 0
[copyright] => 0
[original] => 0
[emphasis] => 0
)
[version] => 1
[layer] => 3
[channelmode] => joint stereo
[channels] => 2
[sample_rate] => 44100
[protection] =>
[private] =>
[modeextension] =>
[copyright] =>
[original] =>
[emphasis] => none
[padding] => 1
[bitrate] => 128000
[framelength] => 418
[bitrate_mode] => cbr
)
)
[playtime_seconds] => 285.9885625
[tags_html] => Array
(
[id3v1] => Array
(
[title] => Array
(
[0] => ÌÓÍö
)
[artist] => Array
(
[0] => ËïÑà×Ë
)
[album] => Array
(
[0] => ·çóÝ
)
[year] => Array
(
[0] => 2001
)
[comment] => Array
(
[0] => http://51music.dhs.org
)
[track] => Array
(
[0] => 4
)
)
[id3v2] => Array
(
[url_user] => Array
(
[0] => http://www.cy2002.com
)
[comments] => Array
(
[0] => http://51music.dhs.org
)
[year] => Array
(
[0] => 2001
)
[album] => Array
(
[0] => ·çóÝ
)
[artist] => Array
(
[0] => ËïÑà×Ë
)
[title] => Array
(
[0] => ÌÓÍö
)
[track_number] => Array
(
[0] => 4
)
)
)
[bitrate] => 128000
[playtime_string] => 4:46
)