Pros:
- Users can get info from remote files without downloading them entirely.
Cons:
- The amount downloaded (currently 300000) is a lot. It can even be more, I would say the safe limit is 1,000,000.
Code: Select all
<?php
$url='http://getid3.org/demo/test.mp3'; // define the remote mp3 file
if($url){
$filename = tempnam('/tmp','getid3');
if (file_put_contents($filename, file_get_contents($url, false, null, 0, 300000))) {
if (require_once('getid3/getid3.php')) {
$getID3 = new getID3;
$ThisFileInfo = $getID3->analyze($filename);
}
unlink($filename);
}
}
$bitratez=$ThisFileInfo[audio][bitrate]; // get the bitrate from the audio file
$headers = get_headers($url, 1); // Get the headers from the remote file
if ((!array_key_exists("Content-Length", $headers))) { return false; } // Get the content length from the remote file
$filesize= round($headers["Content-Length"]/1000); // Make the failesize into kilobytes & round it
$contentLengthKBITS=$filesize*8; // make kbytes into kbits
$bitrate=$bitratez/1000; //convert bits/sec to kbit/sec
$seconds=$contentLengthKBITS/$bitrate; // Calculate seconds in song
$playtime_mins = floor($seconds/60); // get the minutes of the playtime string
$playtime_secs = $seconds % 60; // get the seconds for the playtime string
if(strlen($playtime_secs)=='1'){$zero='0';} // if the string is a multiple of 10, we need to add a 0 for visual reasons
$playtime_secs = $zero.$playtime_secs; // add the zero if nessecary
$playtime_string=$playtime_mins.':'.$playtime_secs; // create the playtime string
echo $playtime_string;
?>