別のサーバー(Image)に1つの画像がありますが、この画像をfile_get_contents()
関数で取得すると返されます
見つからないエラー
このImageを生成します。
file_put_contents(destination_path, file_get_contents(another_server_path));
助けてください。それらの画像を取得する別の方法がある場合。
これを試して。
URL の特殊文字に問題があります。URL ベース名から特殊文字をデコードする必要があります。
$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);
注: ファイル名にスペースを含む画像を保存するのはよくないので、このファイルを適切な名前で保存する必要があります。