[求助]通過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);
?>
檢查代碼中的空格並將其刪除。主要通過縮進。當執行不直接在頁面上寫東西的代碼時,不要關閉php,這是一個好習慣。 – Vladimir
確保'<?php'之前或'?>'之後沒有換行符或空格。在發送文件之後'退出'也是一個好主意,爲了安全起見。 –
您可以檢查編碼,例如一邊是UTF-8,另一邊是ISO。如果您的php腳本不在相同的編碼,它可能會導致一些校驗和錯誤 –