[eluser]toopay[/eluser]
Since CI also use ob_start() and ob_end_clean(), so that If you use those, you should provide proper validation (which i'm not see so far in your code, as i said above).
And i've just notice, that you write this on helper file instead library file. I suggest you modify your helper into some Library/Class, so you can do more proper validation, or even use download helper, something like...
Code:
/* [NOT TESTED] */
class userExel{
protected $ob_level;
protected $CI;
public function __construct()
{
// Set the super object to a local variable for use later
$this->CI =& get_instance();
$this->ob_level = ob_get_level();
log_message('debug', "User Excell Class Initialized");
}
//... now, since you declared this as class, you can do proper validation like this
function somefunction($some_var)
{
if (ob_get_level() > $this->ob_level + 1) ob_end_flush();
ob_start();
//...do something else
$buffer = ob_get_contents();
ob_end_clean();
return $buffer;
}
//... the rest of your code
function zipFilesAndDownload($file_name,$archive_file_name)
{
//create the object
$zip = new ZipArchive();
//create the file and throw the error if unsuccessful
if ($zip->open($archive_file_name, ZIPARCHIVE::CREATE )!==TRUE)
{
exit("cannot open <$archive_file_name>\n");
}
//add each files of $file_name array to archive
$zip->addFromString("leads/export.xls",$file_name);
$zip->close();
//then send the headers to force download the zip file
/*
header('Content-Type: application/vnd.ms-excel');
header("Content-Disposition: attachment;filename=$archive_file_name");
header('Cache-Control: max-age=0');
header("Content-Transfer-Encoding: binary");
header('Pragma: public');
readfile($archive_file_name);
exit;
*/
// Here you can use CI Download helper
$this->CI->load->helper('download');
$data = file_get_contents("/path/to/your_file.zip"); // Read the file's contents
$name = 'download_somefile.zip';
force_download($name, $data);
}
}