假设保存在磁盘上的文件:
HTTP/1.1 200 OK
Date: Thu, 28 Jun 2012 22:11:14 GMT
Pragma: no-cache
Cache-Control: must-revalidate, no-store
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Content-Length: 1234
Connection: close
Content-Type: text/html
<html ....
php中是否有内置函数输出文件,同时识别其中的标题并正确发送?
答案 0 :(得分:1)
不,没有。你必须自己实施一个。
答案 1 :(得分:0)
它不存在,但您可以使用以下
$file = "file.html";
var_dump(fileHeaders($file));
输出
array
0 => string 'HTTP/1.1 200 OK' (length=15)
1 => string 'Date: Thu, 28 Jun 2012 22:11:14 GMT' (length=35)
2 => string 'Pragma: no-cache' (length=16)
3 => string 'Cache-Control: must-revalidate, no-store' (length=40)
4 => string 'Expires: Thu, 01 Jan 1970 00:00:00 GMT' (length=38)
5 => string 'Content-Length: 1234' (length=20)
6 => string 'Connection: close' (length=17)
7 => string 'Content-Type: text/html' (length=23)
8 => string '' (length=0)
使用的功能
function fileHeaders($file) {
$content = file_get_contents($file, null, null, 0, 1000);
$content = trim($content);
if (stripos($content, "HTTP") === 0) {
return array_map("trim", explode("\n", strtok($content, "<")));
}
return false;
}