getID3 cannot directly parse remote files via URL. You must first download the file to a local temporary location before calling analyze().
Since version v1.9.9-20150212, the analyze() method accepts optional second and third parameters: original_filesize and original_filename. This allows you to download only a portion of a large remote file while still obtaining accurate playtime estimates, provided the file format only requires the beginning of the file for analysis.
// Copy remote file locally to scan with getID3()
$remotefilename = 'http://www.example.com/filename.mp3';
if ($fp_remote = fopen($remotefilename, 'rb')) {
$localtempfilename = tempnam('/tmp', 'getID3');
if ($fp_local = fopen($localtempfilename, 'wb')) {
while ($buffer = fread($fp_remote, 32768)) {
fwrite($fp_local, $buffer);
}
fclose($fp_local);
$remote_headers = array_change_key_case(get_headers($remotefilename, 1), CASE_LOWER);
$remote_filesize = (isset($remote_headers['content-length']) ? (is_array($remote_headers['content-length']) ? $remote_headers['content-length'][count($remote_headers['content-length']) - 1] : $remote_headers['content-length']) : null);
// Initialize getID3 engine
$getID3 = new getID3;
$ThisFileInfo = $getID3->analyze($localtempfilename, $remote_filesize, basename($remotefilename));
// Delete temporary file
unlink($localtempfilename);
}
fclose($fp_remote);
}