在手机上下载时,.apk文件的php标头无效

jax*_*jax 0 php android

我想下载一个由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);
  }
 }
Run Code Online (Sandbox Code Playgroud)

我的设置:

Fedora Core 10

PHP 5.2.9

阿帕奇

Rom*_*rik 6

以下适用于运行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');
?>
Run Code Online (Sandbox Code Playgroud)

运行PHP版本5.2.4-2ubuntu5.6.

如果您提供有关设置的更多详细信息,我们可能会提供更多帮助.