【发布时间】:2010-07-29 16:38:38
【问题描述】:
我正在尝试下载由 php 页面输出的 Android APK 文件。我有以下内容,它可以在 Firefox 上运行,但不能在手机上运行。
Firefox 使用 apk 扩展下载,但旁边有一个小 Firefox 图标。
手机下载后缀为.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
阿帕奇
【问题讨论】:
-
我相信注释掉的内容类型是正确的。
-
那是我原来的,但也没有用
-
我遇到了类似的问题。我解决了它。你可以看看我的帖子,可能对你有帮助。 stackoverflow.com/questions/3673008/…