rta*_*oni 2 php apache header content-length
我通过以下方式设置标题:
header('Content-Length: ' . filesize($strPath));
Run Code Online (Sandbox Code Playgroud)
在我的带有 ZendServer 的 PC 上它工作正常,我可以下载文件大小正确的文件。在生产服务器上,一个带有 Apache 和编译 PHP 的 Solaris,我得到一个文件大小为零的文件,所以是一个空文件。
有配置参数吗?可以阻止设置“内容长度:1222”的东西?
谢谢。
编码:
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
require 'includes/prepend.inc.php';
require __ADMIN_DIR__.'/AdminInfo.php';
$intFile = QApplication::QueryString('fileID');
if($intFile == '') die('Error: missing ID');
$objFile = File::Load($intFile);
$blnRight = false;
$objAdminInfo = new AdminInfo();
if($objAdminInfo->isAdmin()) {
$blnRight = true;
}
else {
$objSecMan = new SecurityManager(
'file:'.$objFile->FileID,
$objAdminInfo->getUserID()
);
$blnRight = $objSecMan->processResource('view');
}
// if the user can modify and or publish, can even view the file
if(!$blnRight) {
$blnRight = $objSecMan->processResource('modify');
if(!$blnRight) {
$blnRight = $objSecMan->processResource('publish');
}
}
//$strPath = __UPLOADS__.DIRECTORY_SEPARATOR.$objFile->FileID;
$strPath = 'subdept.csv';
if (file_exists($strPath) && $blnRight) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.$strPath);//$objFile->Filename);
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($strPath));
ob_clean();
flush();
readfile($strPath);
exit;
}
else {
die('Restricted access');
}
?>
Run Code Online (Sandbox Code Playgroud)
当我在 $strPath 之前评论代码时,它可以工作,所以它一定是该死的框架中的东西。我想扔掉整个 CMS。
检查传输编码标头。如果传输编码是分块的,则不会设置 Content-Length 字段
可能的原因是 ZendServer 没有进行分块编码,而 Apache 却做了
详情请参阅以下链接
http://en.wikipedia.org/wiki/Chunked_transfer_encoding
http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html