使用php的Apk下载提供了未定义的功能,但在浏览器刷新后可以下载

使用php的Apk下载提供了未定义的功能,但在浏览器刷新后可以下载,php,apk,Php,Apk,我在Firefox桌面浏览器和手机上得到一个未定义的输出。当我刷新浏览器时,下载对话框启动并下载apk文件。 关于如何在空白页面中绕过未定义的输出并立即进入下载对话框,有什么想法吗?试试以下方法: $file = 'myfile.apk'; $filename ="MYAPP"; if (file_exists($file)) { header('Content-Description: File Transfer'); header('Content-Type: applica

我在Firefox桌面浏览器和手机上得到一个未定义的输出。当我刷新浏览器时,下载对话框启动并下载apk文件。 关于如何在空白页面中绕过未定义的输出并立即进入下载对话框,有什么想法吗?

试试以下方法:

$file = 'myfile.apk';
$filename ="MYAPP";
if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/vnd.android.package-archive');
    header("Content-Disposition:attachment; filename=\"$filename\"");
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    exit;
}

你所说的未定义的输出是什么意思?一个空白网页返回的第一行有一个未定义的单词..嗯?真奇怪。。。仅“未定义”无其他内容?在执行浏览器刷新时,仅“下载”对话框启动在其他地方听起来像是错误,但不在脚本的这一部分。顺便说一句,我建议在文件名后面附加.apk。。。
$file = 'myfile.apk';
$filename ="MYAPP";
if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/vnd.android.package-archive');
    header("Content-Disposition:attachment; filename=\"$filename\"");
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    exit;
}
<a href="#" onClick="window.location='download.php'">
  <img src="images/android/android01.jpg"/>Android
</a>