作为记录:它不能在 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);
因此,基本上,加载框架,使用数据库或其他任何东西并自己调用标头函数。希望,这对其他人有帮助。