我需要将图像从 PHP URL 保存到我的 PC。
假设我有一个页面,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);
关于php - 从 PHP URL 保存图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/724391/