2

我在另一台服务器上有一个图像(图像)。但是当我得到这个图像时file_get_contents()它会返回

未找到错误

并生成此Image

file_put_contents(destination_path, file_get_contents(another_server_path));

请帮助我。如果有另一种方法来获取这些图像。

4

2 回答 2

1

尝试这个。

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);
于 2016-09-02T10:48:23.950 回答
0

从另一台服务器下载副本文件的另一种方法是使用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);

注意:在文件名中保存带有空格的图像是不好的做法,因此您应该使用正确的名称保存此文件。

于 2016-09-02T07:46:54.090 回答