使用curl下载间接映像文件 [英] use curl to download indirect image file

查看:156
本文介绍了使用curl下载间接映像文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从以下代码从网址下载图片文件,但它不会从服务器返回正确的内容。该图像可以通过加载网址或在shell模式下使用curl下载,但不能在php执行中在浏览器中呈现。在php执行中,从服务器返回的头的内容类型是' text / html '而不是' image / jpeg

I am try to download image files from url from the following code, but it doesn't return the right content from the server. The image can be rendered in browser by loading the url or downloaded using curl in shell mode, but not in php execution. In php execution, the header's content type returned from the server is 'text/html' instead of 'image/jpeg' which it supposes to be.

任何人都有任何想法?

$url = 'http://count.koubei.com/showphone/showphone.php?f=jpg&w=104&h=10&bc=255,255,255&fc=0,0,0&fs=10&fn=arial&phone=LTIxMDM3MjIyOTc%3D%23dWBzmKEZpTh7YcWvOw%3D%3D';
$file_handler = fopen('phone.jpeg', 'w');
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_FILE, $file_handler);
curl_setopt($curl, CURLOPT_HEADER, false);

curl_exec($curl);

curl_close($curl);
fclose($file_handler);


推荐答案

为什么不使用file_get_contents

why not just use file_get_contents like this

$img = file_get_contents("http://count.koubei.com/showphone/showphone.php?f=jpg&w=104&h=10&bc=255,255,255&fc=0,0,0&fs=10&fn=arial&phone=LTIxMDM3MjIyOTc%3D%23dWBzmKEZpTh7YcWvOw%3D%3D");
file_put_contents("photo.jpg",$img);

这篇关于使用curl下载间接映像文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆