Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

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);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
535 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...