I am trying to download an Android APK file that is output by a php page. I have the following and it works on firefox but not on the phone.
Firefox downloads with an apk extension but has a little firefox icon next to it.
The phone downloads the file with a .html extension, why is this?
UPDATE: Full source
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');
}
开发者_JAVA百科 else {
header('Content-type: application/vnd.android.package-archive');
header('Content-Disposition: attachment; filename="'.$sanitizedFile.'"');
readfile($path);
}
}
My setup:
Fedora Core 10
PHP 5.2.9
Apache
The following works fine for me on a Nexus One running Android 2.2, as well as in Chrome:
<?php
header('Content-Type: application/vnd.android.package-archive');
header('Content-Disposition: attachment; filename="Foo.apk"');
readfile('Foo.apk');
?>
Running PHP Version 5.2.4-2ubuntu5.6.
If you provide more details on your setup, we may be able to help more.
精彩评论