1

我正在为手机(即运行 Android)提供下载服务,而 Android 似乎只接受特定的 headers。现在这就是我在 Joomla 中尝试做的事情。

    $doc =& JFactory::getDocument();
$doc->setMimeEncoding('application/octet-stream');

这可行,但由于某种原因,Joomla 将 charset=utf-8 添加到我的标题中,因此下载不起作用。我如何摆脱这个字符集(结果证明它对二进制文件毫无用处)?

4

3 回答 3

2

PHP 5.3 引入了header_remove,可能会在您的情况下使用(尽管我对 Joomla 的经验很少)。

于 2012-08-17T15:40:44.327 回答
1

对于 Joomla 2.5(未针对较低或较高版本进行测试)Joomla 附加自己的标题,这就是您需要使用 JResponse::clearHeaders(); 的原因

$filename = basename($file);
ob_end_clean();
JResponse::clearHeaders();
JResponse::setHeader('Content-Type', 'application/octet-stream', true);
JResponse::setHeader('Content-Disposition', 'attachment; filename='.$filename.';', true);
JResponse::sendHeaders();
echo JFile::read($file);
于 2013-03-05T22:09:49.997 回答
0

作为记录:它不能在 Joomla 的 MVC 结构中完成,因为总是附加一个字符集(和其他标题),所以我最终从一个单独的 php 文件导入和初始化 Joomla 的框架,如下所示:

define( '_JEXEC', 1 );

// real path depending on the type of server
// change the number of returns/level needed in your path relative to the position of your script in your directory
define( 'JPATH_BASE', realpath(dirname(__FILE__).'/../../..' ));
define( 'JPATH_COMPONENT', realpath(dirname(__FILE__).'/..' ));
define( 'DS', DIRECTORY_SEPARATOR );

// loading framework of Joomla!
require_once ( JPATH_BASE.DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE.DS.'includes'.DS.'framework.php' );
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();

/* 
... some other joomla stuff ...
*/
header('Content-Disposition: attachment; filename="example.zip"'));
header('Content-Type: application/octet-stream');
readfile($lfile);

因此,基本上,加载框架,使用数据库或其他任何东西并自己调用标头函数。希望,这对其他人有帮助。

于 2012-08-17T20:55:43.707 回答