php – Content-Length标头始终为零
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php – Content-Length标头始终为零,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1964字,纯文字阅读大概需要3分钟。
内容图文
![php – Content-Length标头始终为零](/upload/InfoBanner/zyjiaocheng/704/c00596167fd7415c99a548a110fcc182.jpg)
我按以下方式设置标题:
header('Content-Length: ' . filesize($strPath));
在我的电脑上使用ZendServer它工作正常,我可以下载一个文件大小正确的文件.在生产服务器上,使用Apache和编译PHP的Solaris,我得到一个文件大小等于零的文件,因此是一个空文件.
有配置参数吗?可以阻止设置’Content-Length: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');
}
?>
当我在$strPath之前评论代码时它起作用,所以它必须是血腥框架中的东西.我想抛弃整个CMS.
解决方法:
检查传输编码标头.如果传输编码被分块,则不会设置Content-Length字段
可能的原因是ZendServer没有进行分块编码,而Apache则没有
有关详细信息,请参阅以下链接
http://en.wikipedia.org/wiki/Chunked_transfer_encoding
http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html
内容总结
以上是互联网集市为您收集整理的php – Content-Length标头始终为零全部内容,希望文章能够帮你解决php – Content-Length标头始终为零所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。