这很奇怪.
我有一个脚本,通过浏览器将本地zip文件发送给用户.到目前为止,该脚本运行良好,没有任何问题.今天我的同事告诉我脚本正在发送零长度文件.
一些背景信息:
更新:
is_readable() 返回1$zip_file 保存文件路径$zip_name 持有zip名称error_reporting是On(E_ALL)没有显示有疑问的片段:
if (file_exists($zip_file)) {
header('Content-type: application/zip');
header('Content-disposition: filename="' . $zip_name . '"');
header("Content-length: " . filesize($zip_file));
readfile($zip_file);
exit();
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能轻松调试?
提前谢谢,fabrik
http://www.php.net/manual/en/function.readfile.php#102137:
应该注意的是,在例子中:
header('Content-Length: ' . filesize($file));$ file应该是文件的完整路径.否则将不会始终设置内容长度,通常会导致可怕的"0字节文件"问题.
我的。瘸。过错。对不起大家。
一周前刚刚调整了代码并添加了:
if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) {
ob_start('ob_gzhandler');
} else {
ob_start();
}
Run Code Online (Sandbox Code Playgroud)
是什么导致了这个异常。:(