Cover art save

The place for "I can't figure out how to..." questions.
Post Reply
Joined:Tue Mar 08, 2016 8:17 pm
Are you a spambot?:no
Cover art save

Post by erfiodena » Tue Mar 08, 2016 8:21 pm

Hello guys i have recently used getID3 but i can't figure how to save cover art of a m4a file in my database table in which there is a field of type BLOB. Someone can help me? Thanks.

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

Re: Cover art save

Post by James Heinrich » Tue Mar 08, 2016 8:38 pm

Cover art will be returned under [comments][picture][<key>] -- <key> will be 0 for the first entry but there may be more than one entry (for example, not an m4a file but same returned structure).

Exactly how you put the data in your table will of course depend on your database system. Assuming MySQL, and only taking the first picture if available, something like this should work:

Code: Select all

$getID3 = new getID3;
$ThisFileInfo = $getID3->analyze($filename);

if (!empty($ThisFileInfo['comments']['picture'][0])) {
  mysql_query('INSERT INTO `tablename` (`blobfield`) VALUES ("'.mysql_real_escape_string($ThisFileInfo['comments']['picture'][0]).'")');
You'll have to supply the filename, of course, as well as fill in more of the table structure in the query (table name, you'll no doubt want some identifier so you know what file that image belongs to, etc).

Post Reply