PHP无法在我的服务器上正确下载apk文件

时间:2014-03-08 09:44:18

标签: php file download apk

我必须从我的服务器下载一个apk文件,但我的下载不完整。

这是代码:

header('Content-Type: application/vnd.android.package-archive');
header('Content-Disposition: attachment; filename="Zappapp1.0.apk"');
readfile('Zappapp1.0.apk');

修改

我试试这个,但它不起作用..

$file = 'zappapp.altervista.org/apk/Zappapp1.0.apk';
        if (file_exists($file)) {
             header('Content-Description: File Transfer');
             header('Content-Type: application/vnd.android.package-archive');
             header('Content-Disposition: attachment; filename='.basename($file));
             header('Content-Transfer-Encoding: binary');
             header('Expires: 0');
             header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
             header('Pragma: public');
             header('Content-Length: ' . filesize($file));
             ob_clean();
             flush();
             readfile($file);
             exit;
         }

对不起我的英语,但我是意大利人..

1 个答案:

答案 0 :(得分:3)

你可以试试这也许它可以帮助你.............

$file = '/home/bla-bla/domains/bla-bla.com/file/file.apk'; //not public folder
if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/vnd.android.package-archive');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    exit;
}