dqwh0109 2016-10-08 12:15
浏览 74

HTTP标头内容长度mod_deflate问题

Hi I have a HTTP Header in a file called download.php that forces a download.

The PHP Code:

$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.

.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:

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). 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

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.

  • 写回答

1条回答 默认 最新

  • doujianwei8217 2016-10-08 13:16
    关注

    Found the solution.

    filesize() function does not accept HTTP or HTTPS.

    Changed the file location to the server filepath and is now functioning correctly.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?