2011-06-23 31 views
1
$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); 

    } 

在此代碼中,空白圖像store.not原始圖像存儲。如何從本地服務器保存圖像在YouTube或PHP的本地服務器

回答

4

你只是寫縮略圖的網址而不是圖像的內容。您必須從url獲取圖像內容並將其寫入圖像文件。

以下是捷徑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);