gpt4 book ai didi

php - 使用 cURL php 抓取图像

转载 作者:行者123 更新时间:2023-12-03 21:28:43 24 4
gpt4 key购买 nike

尝试使用 cURL 将图像保存到我的服务器。图像似乎可以下载。它显示正确的字节,但是当我链接图像时不起作用。然后我 DL 看到它是一张空白图像。

这是我的代码...它有什么问题?

$ch = curl_init("'. $image .'");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$rawdata=curl_exec ($ch);
curl_close ($ch);

$fp = fopen("$rename.jpg",'w');
fwrite($fp, $rawdata);
fclose($fp);

最佳答案

我测试了你的脚本,它对我来说工作正常,只需删除 $image 的无用双引号和点。

<?
$image ="http://cdn.sstatic.net/stackoverflow/img/sprites.png?v=5";
$rename="123";

$ch = curl_init($image);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$rawdata=curl_exec ($ch);
curl_close ($ch);

$fp = fopen("$rename.jpg",'w');
fwrite($fp, $rawdata);
fclose($fp);
?>

关于php - 使用 cURL php 抓取图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10890617/

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