Cover art

The place for "I can't figure out how to..." questions.
Post Reply
matty
User
Posts: 2
Joined: Sat Mar 22, 2008 5:45 pm

Cover art

Post by matty » Sat Mar 22, 2008 5:50 pm

I'm trying to get the cover art out and save it to the file system but am having problems. I'm copying the file to my server and then analysing it.
// Get all of the stuff from the mp3 file
$remotefilename = $url;
if ($fp_remote = fopen($remotefilename, 'rb')) {
$localtempfilename = tempnam('/tmp', 'getID3');
if ($fp_local = fopen($localtempfilename, 'wb')) {
while ($buffer = fread($fp_remote, 8192)) {
fwrite($fp_local, $buffer);
}
fclose($fp_local);
$getID3 = new getID3;
$fileinfo = $getID3->analyze($localtempfilename);
getid3_lib::CopyTagsToComments($fileinfo);
$pic = $fileinfo[id3v2][APIC][0][data];

// Delete temporary file
unlink($localtempfilename);
}
fclose($fp_remote);
}
I get the following error with the line:
$pic = $fileinfo[id3v2][APIC][0][data];

Notice: Undefined index: APIC in ...

I've read all the forum posts on this but can't see what's going wrong. I'm running PHP 4.

matty
User
Posts: 2
Joined: Sat Mar 22, 2008 5:45 pm

Actually

Post by matty » Sat Mar 22, 2008 6:18 pm

Actually, don't worry, I solved the problem. I found this code:
$getID3->analyze($filename);
if (isset($getID3->info['id3v2']['APIC'][0]['data'])) {
$cover = $getID3->info['id3v2']['APIC'][0]['data'];
} elseif (isset($getID3->info['id3v2']['PIC'][0]['data'])) {
$cover = $getID3->info['id3v2']['PIC'][0]['data'];
} else {
$cover = null;
}
http://labs.spaceshipnofuture.org/icky/GetID3/

Post Reply