开发者

use curl to download indirect image file

开发者 https://www.devze.com 2022-12-13 19:05 出处:网络
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 load开发者_开发技巧ing the url or d

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 load开发者_开发技巧ing 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.

Anyone has any ideas about this?

$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);


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消