【问题标题】:php headers for a .apk file is not working when downloading on the phone在手机上下载时,.apk 文件的 php 标头不起作用
【发布时间】: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/…

标签: php android


【解决方案1】:

在运行 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。

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

【讨论】:

  • 我使用 readFile 等将其更改为与您的版本完全相同,但它仍然将 .html 附加到末尾。
  • 我在问题中添加了完整的来源。这实际上来自 Joomla 1.5 组件。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多