gpt4 book ai didi

php - 从 PHP URL 保存图像

转载 作者:IT老高 更新时间:2023-10-28 11:36:47 25 4
gpt4 key购买 nike

我需要将图像从 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com