通过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

点赞