如何在php或cakephp中从youtube保存本地服务器上的图像

问题描述

||
$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);

    }
在此代码中,“空白图片存储”不是原始图片存储。     

解决方法

        您只是在写缩略图网址,而不是图片内容。您必须从url获取图像的内容并将其写入图像文件。 以下是
fopen
fwrite
的快捷方式。
$img_content=file_get_contents($thumbnail_url);
file_put_contents($fullpath,$img_content );
要么
$img_content=file_get_contents($thumbnail_url);
$fp = fopen($fullpath,\'x\');
fwrite($fp,$img_content);
fclose($fp);