2011-05-17 20 views

回答

0
$twitsImg ='http://a0.twimg.com/profile_images/1260994338/P3030586-2_bigger.jpg'; 

$twit=file_get_contents($twitsImg); 
$new_img = basename($twitsImg); 

file_put_contents($new_img,$twit); 
0

您所遇到的問題是,PHP ini文件變量allow_url_fopen被關閉,因爲它應該是。你需要使用cURL來獲取文件。默認情況下,cURL通常安裝在Web服務器上。此示例適用於我的網站:

<?php 
function save_image($img,$path){ 
    $ch = curl_init($img); 
    curl_setopt($ch, CURLOPT_HEADER, 0); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_BINARYTRANSFER,1); 
    $data=curl_exec($ch); 
    curl_close ($ch); 
    if(file_exists($path)){ 
     unlink($path); 
    } 
    $fp = fopen($path,'x'); 
    fwrite($fp, $data); 
    fclose($fp); 
} 

save_image("http://a0.twimg.com/profile_images/1260994338/P3030586-2_bigger.jpg","up/file2.jpg"); 
?> 

此外,請確保您在目標文件夾中設置了正確的CHMOD(775)。

相關問題