Kat*_*ata 2 php curl image download
我尝试从以下代码中下载url中的图像文件,但它不会从服务器返回正确的内容.可以通过加载url在浏览器中呈现图像,或者在shell模式下使用curl下载,但不能在php执行中下载.在php执行中,从服务器返回的标题的内容类型是' text/html'而不是' image/jpeg'它应该是.
任何人对此都有任何想法?
$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);
Run Code Online (Sandbox Code Playgroud)
为什么不直接使用这样的file_get_contents
$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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6941 次 |
| 最近记录: |