我正在尝试通过 PHP 实现间接下载。在客户端,我使用 md5 验证下载的文件是否正确。
当我直接下载文件时(http://server/folder/file.apk http://server/folder/file.apk)我得到与文件系统上相同的 md5 校验和,但是当我通过 PHP 脚本下载它时(http://server/some_page.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);
?>
我发现了错误:
$name_file="test2.apk";
$path="/home/user/public_html/apk/";
$dimension_file=(string)filesize($name_file); //<-- HERE! ---
我仅使用文件名而不是使用完整路径来检索大小
filesize($name_file) ---> filesize( $path . $name_file)
错误被隐藏
header("Content-Type: application/vnd.android.package-archive");
并将 php 错误响应添加到下载文件的内容中。
因此,我建议遇到此类问题的人在调试时评论“Content-Type”,以查看 php 代码中是否存在一些错误,并且当所有代码似乎都可以工作时重新启用“Content-Type”标头。
在我的服务器空间中的代码之前
readfile($path.$name_file);
对校验和没有影响
感谢 Vladimir 和 Rocket 提供的良好练习技巧
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)