我使用PHP根據用戶提供的輸入在apache服務器上編譯應用程序,然後使用readfile()
方法嚮應用程序提供應用程序。
我面臨的問題是,實際下載應用程序時,.apk文件正在以文本文件的形式打開。
使用PHP從服務器下載apk時的垃圾輸出
我已經在PHP代碼中添加了Android應用程序MIME類型。
我的PHP代碼:
<?php
echo "Please wait while the app is being generated, it can take around 10 minutes for the build to finish.The completed app will be mailed to you ";
if(isset($_POST['timestamp']))
{
$uid = $_POST['timestamp'];
exec("sudo python /var/www/html/appgenserver.py $uid");
header("Content-Description: File Transfer");
header("Content-Type: application/vnd.android.package-archive");
header("Content-Transfer-Encoding: Binary"); //Adding or removing this hass no effect
header('Content-Disposition: attachment; filename="Foo.apk"');
ob_clean();
flush();
readfile("/var/www/html/".$uid."/releaseapk.apk");
exit();
}
?>
任何幫助,將不勝感激。
註釋掉echo語句了。但仍然是同樣的錯誤。 –
我會從這個頁面上的一個例子開始http://php.net/manual/en/function.readfile.php並讓它起作用,然後每次添加一個附加的東西。 –
謝謝, 但我通過其他方法修復了它,並且已經回答了問題 –