Hi,
the best solution in this case would be create this file in download script and remove it at the end.
<?php
// here get some params from the user. For example
if(!isset($_REQUEST['cid']) || !isset($_REQUEST['some_data'])) die('Invalid usage');
$cid = $_REQUEST['cid'];
$some_data = $_REQUEST['some_data'];
define('CID', $cid);
define('READ_ONLY_SESSION',true);
require_once('../../../include.php'); // path to include in main EPESI dir.
// load epesi modules
ModuleManager::load_modules();
// check if user is logged in
if (!Base_AclCommon::is_user())
die('user not logged in');
// create file
$filename = YourModuleCommon::create_file($some_data);
// read file into memory
$buffer = file_get_contents($filename);
//remove created file
@unlink($filename);
//// alternative solution here is to create a file into buffer
// $buffer = YourModuleCommon::create_file_contents($some_data);
if (headers_sent())
die('Some data has already been output to browser, can\'t send file');
else {
$filename = 'testfilename.xls';
header('Content-Type: application/xls'); // apply your format here
header('Content-Length: '.strlen($buffer));
header('Content-disposition: attachement; filename="'.$filename.'"');
header('Content-Transfer-Encoding: binary');
echo $buffer;
}
?>
Then create a link to this file:
$href = "modules/YourModule/download.php?" . http_build_query(array('cid' => CID, 'some_data' => $my_data));
echo "<a href=\"$href\" target=\"_blank\">Download</a>";
// or
Base_ActionBarCommon::add('report', __('Export'), " href=\"$href\" ");
Regards,
Adam