gpt4 book ai didi

php - 从 cURL 获取内容类型

转载 作者:可可西里 更新时间:2023-10-31 23:03:10 26 4
gpt4 key购买 nike

这对于获取标题非常有效

 $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, 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);
$contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
echo $contentType;
echo "<br/>";
curl_close ($ch);
echo "<pre>";
print_r($content);
?>

关于php - 从 cURL 获取内容类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9905224/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com