duanna2026 2014-02-26 15:33
浏览 97

PHP:下载* .tar.gz文件会增加文件大小并更改MD5

I need to offer downloadable *.tar.gz files on a website. For each file, I pre-generated MD5 checksums (and present them alongside the download links, for checking after the download). However, both the file size and the MD5 checksum change after a file was downloaded.

I use the following PHP headers etc.:

header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=\"".basename($filename)."\";");
header("Content-Type: application/octet-stream");
header("Content-Encoding: binary");
header("Content-Length: ".filesize($filepath.$filename));
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private");
header("Pragma: public");
ob_clean();
readfile($filepath.$filename);

When downloading the file directly using curl, I get:

file size: 440875
MD5: f03a0995aec6f2f5f8810b635a6829b8

which is correct!

However, when downloading from the website, I get:

file size: 2488320
MD5: 953db14625c978e387540b6742121309

which is the problem!

What can I do to change this?

  • 写回答

1条回答 默认 最新

  • duan0531 2014-03-01 22:49
    关注

    I was using Safari when I encountered this problem. Using other browsers (Chrome and Firefox), my php headers performed as expected.

    On further research I found that Safari is bound to such problems. Here, I was using a php redirect to the *.tar.gz file I provide for download. Using the direct path link to the file did not cause any problems. Only under Safari the file is downloaded and apparently "unzipped" automatically, i.e. removing the .gz extension and creating a larger downloaded file (where MD5 is of course different).

    I am a bit disappointed that all other browsers I tested do the right thing, while only Safari has this problem.

    评论

报告相同问题?

悬赏问题

  • ¥15 14名同学选出十名到西和,礼县,武都宕昌参加实习,每个学校一个人
  • ¥15 请问如何在openpcdet上对KITTI数据集的测试集进行结果评估?
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路