php – 从cURL获取Content-Type

前端之家收集整理的这篇文章主要介绍了php – 从cURL获取Content-Type前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这很有助于获得标题
$imageurl = "http://p.twimg.com/AW2-vIUCAAE_1FN.png";

  $ch = curl_init();
  curl_setopt ($ch,CURLOPT_RETURNTRANSFER,1);
  curl_setopt ($ch,CURLOPT_URL,$image_url);
  curl_setopt ($ch,CURLOPT_CONNECTTIMEOUT,20);
  curl_setopt ($ch,CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']);
  curl_setopt ($ch,CURLOPT_FOLLOWLOCATION,true);
  curl_setopt($ch,CURLOPT_HEADER,true); 
  curl_setopt($ch,CURLOPT_NOBODY,true);

  $content = curl_exec ($ch);

  curl_close ($ch);

  print_r($content);

回国

HTTP/1.1 200 OK
Server: Nginx
X-peep-host: den2twapi014
Last-Modified: Mon,15 Aug 2011 03:41:50 GMT
ETag: "7283847-dbb8-4aa830b1dabf0"
Accept-Ranges: bytes
Content-Length: 56248
Cache-Control: public,max-age=21600
Expires: Wed,28 Mar 2012 15:53:57 GMT
Content-Type: image/png
X-CDN: AKAM
Date: Wed,28 Mar 2012 09:53:57 GMT
Connection: keep-alive

回应Content-Type的最佳方式是什么?

试试这个:-
<?PHP
$image_url = "http://p.twimg.com/AW2-vIUCAAE_1FN.png";

  $ch = curl_init();
  curl_setopt ($ch,true);

  $content = curl_exec ($ch);
  $contentType = curl_getinfo($ch,CURLINFO_CONTENT_TYPE);
    echo $contentType;
    echo "<br/>";
  curl_close ($ch);
    echo "<pre>";
  print_r($content);
  ?>
原文链接:https://www.f2er.com/php/138361.html

猜你在找的PHP相关文章