remote files. getting partial file, APIC

The place for "I can't figure out how to..." questions.
Post Reply
Posts: 2
Joined: Sun Dec 10, 2006 10:59 am

remote files. getting partial file, APIC

Post by cjm771 » Sun Dec 10, 2006 11:03 am

Hi I wanted to get the Id3 tags (artist/album/song/album art[APIC]) of various mp3s, but only downloading a few bytes from the beginning and ending of the file as stated in a previous post. But I recieve this error.I believe it doesn't read all of the APIC data? Is there a way to see if APIC, read all of the APIC tag and then stop reading? Or is this not the is much appreciated thanks.

Array ( [0] => error parsing "APIC" (950 bytes into the ID3v2.3 tag).
(ERROR: $frame_size (174448) > strlen($framedata) (0))

James Heinrich
getID3() v1 developer
Posts: 1477
Joined: Fri May 04, 2001 4:00 pm
Are you a spambot?: no
Location: Northern Ontario, Canada

Post by James Heinrich » Sun Dec 10, 2006 11:53 am

APIC (Attached PICture) frames can be quite large, anywhere from a few kB to a few hundred kB (I've seen 500+kB images embedded in ID3v2 tags).

I suppose the only way to guarantee you read enough data, beyond simply downloading most/all of the file, would be to download a small amount of data (4kB for example) that would suffice for most ID3v2 tags, attempt to parse it, and then check if $info[id3v2][headerlength] >= the amount of data you downloaded, and if you didn't grab enough data, download the correct amount and re-analyze.

Posts: 2
Joined: Sun Dec 10, 2006 10:59 am

Post by cjm771 » Mon Dec 11, 2006 12:12 am

Ok I tried to edit it to check until the headerlength is larger than the bytes to get. But it still has same error



function transfer_id3_header_and_footer($ch, $url, $file, $size = 0) {
if (!$fp = fopen($file, "wb")) {
echo 'Error opening temp file for binary writing';
return false;
} else if (!$urlp = fopen($url, "r")) {
echo 'Error opening URL for reading';
return false;
// try{
$to_get = 65536;
if ($already==false)
$to_get2=$to_get;// 64 KB
$chunk_size = 4096; // Haven't bothered to tune this, maybe other values would work better??
$got = 0; $data = null;

// Grab the first 64 KB of the file
while(!feof($urlp) && $got < $to_get2) {
$data = $data . fgets($urlp, $chunk_size);
$got += $chunk_size;
fwrite($fp, $data);

// Grab the last 64 KB of the file, if we know how big it is.
if ($size > 0) {
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RESUME_FROM, $size - $to_get*2);

// Now $fp should be the first and last 64KB of the file!!

// } catch (Exception $e) {
// @fclose($fp);
// @fclose($urlp);
// echo 'Error transfering file using fopen and cURL !!';
// return false;
// }

return true;
if (transfer_id3_header_and_footer(curl_init(), $remotefilename, "temp.txt")==true)
$getID3 = new getID3;

$ThisFileInfo = $getID3->analyze("temp.txt");
}while($ThisFileInfo[id3v2][headerlength] >= $to_get2);


Posts: 2
Joined: Mon Jan 29, 2007 10:33 pm

Post by Zaid » Mon Jan 29, 2007 10:38 pm

Hey guys,
Has there been any advance on this topic?

You've mentioned that what you're attempting is a continuation of another thread...but I cant find it, could you provide a URL?


Post Reply