微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

[解决了]

我正在尝试通过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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐