试图卷曲获取图像,但我得到奇怪的结果
这是我的curl函数:
function curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'picturecookies.txt');
curl_setopt($ch, CURLOPT_REFERER, "http://www.google.com/");
curl_setopt($ch, CURLOPT_URL, $url);
$return = curl_exec($ch);
return $return;
}
我试图获取的示例图像:
http:// /static.fjcdn.com/large/pictures/39/29/3929d8_2637027.jpg
当我尝试使用curl获取图像时,我每次只得到一个具有随机文件大小的文件。 这是连续返回 6 次的字节列表;
12 654
12 627
12 632
12 632
12 583
12 627
示例图像是 655kB
我在这里做错了什么?
编辑:
我找到了原因:> 图像受热链接保护。 只需将引用地址更改为显示图像的 url 即可解决此问题。
this is my curl function:
function curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'picturecookies.txt');
curl_setopt($ch, CURLOPT_REFERER, "http://www.google.com/");
curl_setopt($ch, CURLOPT_URL, $url);
$return = curl_exec($ch);
return $return;
}
an example image im trying to get:
http://static.fjcdn.com/large/pictures/39/29/3929d8_2637027.jpg
when i try getting the image with curl, i only get a file with random filesizes each time.
heres a list of bytes returned 6 times in a row;
12 654
12 627
12 632
12 632
12 583
12 627
the example image is 655kB
what am i doing wrong here?
EDIT:
I found why :>
The images are hotlink protected.
It was simply solved by changing the referer to the url the image was presented on.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能会在没有注意到的情况下被重定向到有趣的垃圾索引页面;-)
You are probably getting redirecteed to the funnyjunk index page without noticing ;-)