保存来自php url的图像


我需要将图像从PHP URL保存到我的电脑。 比方说,我有一个页面, http://example.com/image.php
`,拿着一个“花”图像,没有别的。我怎样才能保存这个图像从一个新的名称(使用PHP)的URL?

如果您将allow_url_fopen设置为true

$url = 'http://example.com/image.php';
$img = '/my/folder/flower.gif';
file_put_contents($img, file_get_contents($url));

另外使用 cURL

$ch = curl_init('http://example.com/image.php');
$fp = fopen('/my/folder/flower.gif', 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);

copy('http://example.com/image.php', 'local/folder/flower.jpg');

未经作者同意,本文严禁转载,违者必究!