且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我如何使用curl在头文件中获取文件名?

更新时间:2022-04-11 08:43:15

创建一个读取头文件并自行解析的回调函数。例如:

Create a callback that reads headers, and parse them yourself. Something like:

function readHeader($ch, $header)
{
          global $responseHeaders;
          $url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
          $responseHeaders[$url][] = $header;
      return strlen($header);
}

 ... curl stuff ...
 // if you need to call a class method use this:
 // curl_setopt($ch, CURLOPT_HEADERFUNCTION, array(&$this,'readHeader'));
 // for a non class method use this
 curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'readHeader');
 $result = curl_exec($ch);

 // all headers are now in $responseHeaders