Content-Length 헤더는 항상 영
-
20-09-2019 - |
문제
내가 설정한 헤더에 다음과 같은 방법으로:
header('Content-Length: ' . filesize($strPath));
On my PC ZendServer 동 파일을 다운로드할 수 있는 정확한 파일의 크기입니다.에서 생산 server,Solaris 아파치 컴파일하 PHP,내가 가진 파일의 파일 크기 제로,그래서 빈 파일입니다.
가 설정 매개 변수는?언을 방지할 수 있는 설정'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 그것은 작품,그래서 그것은 무언가가 있어야 한 피 framework.하고 싶은 전체 CMS 습니다.
해결책
전송 인코딩 헤더를 확인하십시오. 전송 인코딩이 청크 인 경우 컨텐츠 길이 필드가 설정되지 않습니다.
가능한 원인은 Zendserver가 청크 인코딩을하지 않는 반면 Apache는
자세한 내용은 다음 링크를 참조하십시오
다른 팁
는지 확인하는 파일이 실제로 존재에서 지정한 경로(is_file
검사를 모두 실존일 경우는 일반 파일)를 읽을 수 있는(is_readable
전)보내는 클라이언트입니다. filesize
환 false 오류가 발생했습니다.그래서 그 원인이 될 수 있습니다 당신의 값이 0 또는 값이 비어 있을 Content-Length.
그리고, 페르디난드 Beyer 이미 언급한, 는지 확인하는 스크립트는 휴대용 및 처리할 수 있는 다양한 환경에 적합합니다.
파일이 프로덕션 서버에 존재한다고 확신합니까? 어쩌면 그것은 사례 민감도 문제 일 수도 있습니다 (예 : "파일"및 "파일"은 Windows에서는 동일하지만 UNIX에서 다릅니다)? Apache/PHP를 실행하는 사용자가 읽기 액세스 권한이 있습니까?
오류를 활성화하면 오류가 발생합니까?
error_reporting(E_ALL);
ini_set('display_errors', '1');
문제는 Apache가 다운로드를 gz다고, 컨텐츠 길이를 수정하거나, 경우에 해당 헤더를 제거하고 추가하는 것이 문제 일 수 있습니다.
내용 인코딩 : 청크
당신은 추가 할 수 있습니다 .htaccess
gzip를 비활성화하려면 Rewriterule :
RewriteRule . - [E=no-gzip:1]