【问题标题】:how to save image at local server from youtube in php or cakephp如何将图像从 youtube 中的 php 或 cakephp 保存到本地服务器
【发布时间】:2026-01-09 02:05:02
【问题描述】:
$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);

    }

在此代码中,空白图像存储。不是原始图像存储。

【问题讨论】:

    标签: php cakephp cakephp-1.3 cakephp-1.2


    【解决方案1】:

    您只是在写缩略图网址而不是图像的内容。您必须从 url 中获取图像的内容并将其写入图像文件。

    下面是fopenfwrite的快捷方式。

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

    【讨论】:

      最近更新 更多