$thumbnail_url = 'http://img.youtube.com/vi/JaFfJN_iKdA/default.jpg';
function save_image_local($thumbnail_url)
{
//for save image at local server
$filename = time().'_hk.jpg';
$fullpath = '../../app/webroot/img/daily_videos/image/'.$filename;
$fp = fopen($fullpath,'x');
fwrite($fp, $thumbnail_url);
fclose($fp);
}
在此代码中,空白图像存储。不是原始图像存储。
答案 0 :(得分:4)
您只是编写缩略图网址而非图像内容。您必须从网址获取图像内容并将其写入图像文件。
以下是fopen
,fwrite
。
$img_content=file_get_contents($thumbnail_url);
file_put_contents($fullpath,$img_content );
OR
$img_content=file_get_contents($thumbnail_url);
$fp = fopen($fullpath,'x');
fwrite($fp, $img_content);
fclose($fp);