加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

通过PHP脚本下载文件导致错误/不同的md5校验和 – 为什么?

发布时间:2020-12-13 16:14:08 所属栏目:PHP教程 来源:网络整理
导读:[解决了] 我正在尝试通过PHP实现间接下载.在客户端,我使用md5验证下载的文件是否正确. 当我直接下载文件(http://server/folder/file.apk)时,我获得与文件系统相同的md5校验和,但是当我通过PHP脚本下载它时(http://server/some_page.php)我得到一个完全不同
[解决了]

我正在尝试通过PHP实现间接下载.在客户端,我使用md5验证下载的文件是否正确.

当我直接下载文件(http://server/folder/file.apk)时,我获得与文件系统相同的md5校验和,但是当我通过PHP脚本下载它时(http://server/some_page.php)我得到一个完全不同的校验和.为什么?

这是我的PHP脚本:

<?php
$name_file="test2.apk";
$path="/home/user/public_html/apk/"; 
$dimension_file=(string)filesize($name_file);

header("Content-Type: application/vnd.android.package-archive ; name=".$name_file);
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".$dimension_file);
header("Content-Disposition: inline; filename=".$name_file);
header("Expires: 0");
header("Cache-Control: no-cache,must-revalidate");
header("Cache-Control: private");
header("Pragma: public");

readfile($path.$name_file);
?>

解决方法

标记这个解决了怎么样?

I found the error: $name_file=”test2.apk”; $path=”/home/user/public_html/apk/”; $dimension_file=(string)filesize($name_file); //<– HERE! — i was retrieving the size using only the name of file instead of using the full path filesize($name_file) —> filesize( $path . $name_file) the error was hidden from header(“Content-Type: application/vnd.android.package-archive”); and the php error response added to the content of the downloaded file. Thanks to Vladimir and Rocket for good practice tips – Zorb yesterday

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读