使用 X-SendFile 将较大的视频文件传送给用户时,我遇到了一个奇怪的行为。服务器响应 412 - 前提条件失败。
如果我禁用 X-SendFile 一切正常,那么它必须与此相关。
部分代码:
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $file_path);
header("Content-type: ". $mime);
finfo_close($finfo);
header('Content-length: '.filesize($file_path));
header('Content-Disposition: inline; filename="'.basename($file_path).'"');
header('X-Sendfile: ' . $file_path );
标题:
Request URL:[redacted]/8c1ab69235fef2009731481d728a3c37.mp4
Request Method:GET
Status Code:412 Precondition Failed
Remote Address:192.168.100.100:80
要求:
Accept:*/*
Accept-Encoding:identity;q=1, *;q=0
Accept-Language:en-US,en;q=0.8,ro;q=0.6,de;q=0.4
Cache-Control:max-age=0
Connection:keep-alive
Cookie:PHPSESSID=rlva81b8gl98flv3r37dd0jtu4
Host:datasolutions.eleap.loc
If-Match:"57e7e64-545404121a47c"
Range:bytes=92078080-
Referer:[redacted]/8c1ab69235fef2009731481d728a3c37.mp4
User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36
响应:
Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection:close
Content-Disposition:inline; filename="8c1ab69235fef2009731481d728a3c37.mp4"
Content-length:0
Content-Type:video/mp4
Date:Wed, 04 Jan 2017 11:08:23 GMT
Expires:Thu, 19 Nov 1981 08:52:00 GMT
Pragma:no-cache
Server:Apache/2.4.20 (Ubuntu)
X-Sendfile:[redacted]/8c1ab69235fef2009731481d728a3c37.mp4
我找不到任何关于这是什么原因的线索,也许你们中的一个人有线索。谢谢你。
更新:这只发生在 Chrome 中。
最佳答案
我在加载 mp4 时遇到了类似的问题(未使用 X-Send)。我发现当我将 Chrome 降级到以前的版本 (54) 时,问题就消失了。几周前出来的新版本 55 似乎已经引入了这个问题。
关于php - 412 - 使用 X-SendFile 传送的文件的前提条件失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41462617/