我有一個形象的另一臺服務器(Image)。但,當我得到這個圖像的file_get_contents()
功能,它會回報獲取圖像的的file_get_contents它返回未找到錯誤
找不到錯誤
並生成此Image。
file_put_contents(destination_path, file_get_contents(another_server_path));
plz幫我。如果有另一種方式來獲取這些圖像。
我有一個形象的另一臺服務器(Image)。但,當我得到這個圖像的file_get_contents()
功能,它會回報獲取圖像的的file_get_contents它返回未找到錯誤
找不到錯誤
並生成此Image。
file_put_contents(destination_path, file_get_contents(another_server_path));
plz幫我。如果有另一種方式來獲取這些圖像。
試試這個。
存在URL特殊字符的問題,那麼您必須從url basename解碼一些特殊字符。
$imgfile = 'http://www.lagrolla.com.au/image/m fr 137 group.jpg';
$destinationPath = '/path/to/folder/';
$filename = basename($imgpath);
$imgpath = str_replace($filename,'',$imgpath).rawurldecode($filename);
copy($imgfile,$destination_path.$filename);
另一種方法是從另一臺服務器下載一份文件是使用curl
:
$ch = curl_init('http://www.lagrolla.com.au/image/data/m%20fr%20137%20group.jpg');
$destinationPath = '/path/to/folder/filenameWithNoSpaces.jpg';
$fp = fopen($destinationPath, 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
注:這是不好的做法將圖像保存在文件命名空間,所以你應該保存適當的名稱此文件。
親愛的那裏沒有問題的文件名,因爲文件名設置爲返回的內容,但它會返回找不到頁面所以.. –
正確的,它只有一些筆記,我知道這不是一個問題。當你試圖用'curl'下載這個文件時發生了什麼? – aslawin
對我來說它工作正常。也許你在PHP配置中沒有'allow_url_fopen'設置爲true? – aslawin
雅親愛的我設置'ini_set('allow_url_fopen',1);'在我的頁面。但直到不工作。 –