我正在尝试下载由php页面输出的Android APK文件。我有以下内容,它适用于Firefox,但不适用于手机。
Firefox下载了apk扩展程序,但旁边有一个小火狐图标。
手机下载扩展名为.html的文件,为什么会这样?
更新:完整来源
function display($tpl = null) {
//SETUP
$appId = JRequest::getInt('id', '0');
$model = &$this->getModel();
$app = $model->getApplication($appId);
if( !$app )
JError::raiseError(500, "Invalid Application ID");
if( empty($app->apk_file) )
JError::raiseError(500, "No APK file found in the database");
$result = $model->newDownload($appId);
//Update the database
if( !$result )
JError::raiseError(500, "Unable to increment download count for ID:".$appId);
//Return the file
$filesFolder = JPATH_COMPONENT_ADMINISTRATOR .DS. 'uploads' .DS. $appId;
//Output the file contents
$sanitizedFolder = JFolder::makeSafe($filesFolder);
$sanitizedFile = JFile::makeSafe($app->apk_file);
$path = $sanitizedFolder .DS. $sanitizedFile;
if( !JFile::exists($path) ) {
JError::raiseError(500, 'File does not exist');
}
else {
header('Content-type: application/vnd.android.package-archive');
header('Content-Disposition: attachment; filename="'.$sanitizedFile.'"');
readfile($path);
}
}
Fedora Core 10
PHP 5.2.9
的Apache
答案 0 :(得分:6)
对于运行Android 2.2和Chrome的Nexus One,以下设置正常:
<?php
header('Content-Type: application/vnd.android.package-archive');
header('Content-Disposition: attachment; filename="Foo.apk"');
readfile('Foo.apk');
?>
运行PHP版本5.2.4-2ubuntu5.6。
如果您提供有关设置的更多详细信息,我们可能会提供更多帮助。