1

我有以下代码使用 getid3 获取 mp3 的专辑封面,但问题是,如何复制此图像并将其放入指定目录?

<?php
require_once('getid3/getid3.php');
$file = "path/to/mp3/file.mp3"; 


$getID3 = new getID3; 
$getID3->option_tag_id3v2 = true;
$getID3->option_tags_images = true;
$getID3->analyze($file); 
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 = "no_cover"; 
} 
if (isset($getID3->info['id3v2']['APIC'][0]['image_mime'])) { 
   $mimetype = $getID3->info['id3v2']['APIC'][0]['image_mime']; 
} else { 
   $mimetype = 'image/jpeg';
} 

if (!is_null($cover)) { 
// Send file 
header("Content-Type: " . $mimetype); 

if (isset($getID3->info['id3v2']['APIC'][0]['image_bytes'])) { 
    header("Content-Length: " . $getID3->info['id3v2']['APIC'][0]['image_bytes']); 
} 

echo ($cover);
?>

这可能吗,如果是的话怎么办?谢谢你的帮助 :)

4

1 回答 1

2

你有没有尝试过:

file_put_contents('<filename>', $getID3->info['id3v2']['APIC'][0]['image_bytes']);
于 2011-10-09T19:11:35.553 回答