我正在使用 get_headers() 并且我想返回内容长度。在下面的数组中,内容长度是密钥号 9,但是我发现内容长度并不总是密钥号 9。我不确定为什么它并不总是相同的密钥?如何搜索数组并始终返回内容长度,无论它是什么键?因为我在函数中使用它,所以文件的实际文件大小不会每次都不同。我的示例代码如下。提前致谢。
Array ( [0] => HTTP/1.0 200 OK [1] => Server: Apache [2] => Pragma: public [3] => Last-Modified: Sun, 01 Apr 2012 07:59:46 GMT [4] => ETag: "1333267186000" [5] => Content-Type: text/javascript [6] => Cache-Control: must-revalidate, max-age=0, post-check=0, pre-check=0 [7] => Expires: Sun, 01 Apr 2012 10:27:26 GMT [8] => Date: Sun, 01 Apr 2012 10:27:26 GMT [9] => Content-Length: 31650 [10] => Connection: close [11] => Set-Cookie: JSESSIONID=M0V4NTTVSIB4WCRHAWVSFGYKE2C0UIV0; path=/ [12] => Set-Cookie: DYN_USER_ID=2059637079; path=/ [13] => Set-Cookie: DYN_USER_CONFIRM=6c6a03988da3de6d704ce37a889b1ec8; path=/ [14] => Set-Cookie: BIGipServerdiy_pool=637871882.20480.0000; path=/ )
function headInfo($url) {
$header = get_headers($url);
$fileSize = $header[9];
return array($header, $fileSize);
}