[英]HTTP Header Content-Length mod_deflate problems
Hi I have a HTTP Header in a file called download.php that forces a download. 嗨,我在一个名为download.php的文件中有一个HTTP标头,它强制下载。
The PHP Code: PHP代码:
$file = 'https://www.website.com/downloads/'.$download->stitle.'.zip';
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
The download starts without a problem, but is always corrupt and the wrong size? 下载开始没有问题,但总是损坏并且大小错误吗?
I am using gzip compression which I assume is causing the content-length to be incorrect for the download as the file is 603kb but the download window is saying 2.2kb. 我正在使用gzip压缩,我认为这会导致下载的内容长度不正确,因为文件为603kb,但下载窗口显示为2.2kb。
.htaccess: .htaccess:
# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain \
text/html \
text/xml \
text/css \
text/x-component \
application/atom+xml \
application/xml \
application/xhtml+xml \
application/rss+xml \
application/javascript \
application/x-javascript \
application/json \
application/vnd.ms-fontobject \
application/x-font-ttf \
application/x-font-woff \
application/font-woff2 \
application/x-web-app-manifest+json \
image/svg+xml \
image/x-icon
# Or, compress certain file types by extension:
<files *.html>
SetOutputFilter DEFLATE
</files>
I added the following to exclude zip files and the download script: 我添加了以下内容以排除zip文件和下载脚本:
SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI \.zip$ no-gzip dont-vary
SetEnvIfNoCase Request_URI download\.php$ no-gzip dont-vary
But the downloaded file is still corrupt and the wrong size (7.7kb). 但是下载的文件仍然损坏并且大小错误(7.7kb)。 The download window now displays no file size.
现在,下载窗口不显示文件大小。
What am I doing wrong? 我究竟做错了什么?
Edit: I am getting the warning: filesize(): stat failed for https://www.website.com/downloads/free-font-family-poppins.zip 编辑:我收到警告:filesize(): https ://www.website.com/downloads/free-font-family-poppins.zip的统计信息失败
If I go to the location the file begins downloading with the correct size, so the file exists, I also changed the permissions of the file and folder to 777 to check it wasn't a permission problem, but still getting the same error. 如果转到该位置,文件将以正确的大小开始下载,因此该文件存在,我还将文件和文件夹的权限更改为777,以检查这不是权限问题,但仍然出现相同的错误。
Found the solution. 找到了解决方案。
filesize() function does not accept HTTP or HTTPS. filesize()函数不接受HTTP或HTTPS。
Changed the file location to the server filepath and is now functioning correctly. 将文件位置更改为服务器文件路径,现在可以正常运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.