在手机上下载时,.apk文件的php头不起作用
我试图下载一个由php页面输出的Android APK文件。我有以下内容,它可以在firefox上使用,但不能在手机上使用 Firefox下载时带有apk扩展,但旁边有一个小Firefox图标 手机下载扩展名为.html的文件,这是为什么 更新:完整来源在手机上下载时,.apk文件的php头不起作用,php,android,Php,Android,我试图下载一个由php页面输出的Android APK文件。我有以下内容,它可以在firefox上使用,但不能在手机上使用 Firefox下载时带有apk扩展,但旁边有一个小Firefox图标 手机下载扩展名为.html的文件,这是为什么 更新:完整来源 function display($tpl = null) { //SETUP $appId = JRequest::getInt('id', '0'); $model = &$this->getModel();
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);
}
}
我的设置:
软呢帽核心10
PHP 5.2.9
Apache在运行Android 2.2的Nexus One上以及在Chrome上,以下功能对我来说都很好:
<?php
header('Content-Type: application/vnd.android.package-archive');
header('Content-Disposition: attachment; filename="Foo.apk"');
readfile('Foo.apk');
?>
在运行Android 2.2的Nexus One上,以及在Chrome上,以下功能对我来说都很好:
<?php
header('Content-Type: application/vnd.android.package-archive');
header('Content-Disposition: attachment; filename="Foo.apk"');
readfile('Foo.apk');
?>
我相信注释掉的内容类型是正确的。这是我最初使用的内容类型,但它不起作用,尽管我遇到了类似的问题。我解决了它。你可以看看我的帖子,它可能会对你有所帮助。我相信注释掉的内容类型是正确的。这是我最初的内容类型,但它不起作用,尽管我有类似的问题。我解决了它。你可以看看我的帖子,它可能会对你有所帮助。我使用readFile ect将其更改为与您的版本完全相同的版本,但它仍然在末尾附加了.html。我为问题添加了完整的源代码。这实际上来自Joomla 1.5组件。我使用readFile ect将其更改为与您的版本完全相同的版本,但它仍然在末尾附加了.html。我为问题添加了完整的源代码。这实际上来自Joomla 1.5组件。