Welcome Guest, Not a member yet? Register   Sign In
Cannot modify header information - headers already sent
#15

[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);
   }
}


Messages In This Thread
Cannot modify header information - headers already sent - by El Forum - 04-30-2011, 01:26 AM
Cannot modify header information - headers already sent - by El Forum - 04-30-2011, 01:29 AM
Cannot modify header information - headers already sent - by El Forum - 04-30-2011, 01:35 AM
Cannot modify header information - headers already sent - by El Forum - 04-30-2011, 01:50 AM
Cannot modify header information - headers already sent - by El Forum - 04-30-2011, 01:56 AM
Cannot modify header information - headers already sent - by El Forum - 04-30-2011, 02:11 AM
Cannot modify header information - headers already sent - by El Forum - 04-30-2011, 02:46 AM
Cannot modify header information - headers already sent - by El Forum - 04-30-2011, 04:50 AM
Cannot modify header information - headers already sent - by El Forum - 04-30-2011, 04:57 AM
Cannot modify header information - headers already sent - by El Forum - 04-30-2011, 05:09 AM
Cannot modify header information - headers already sent - by El Forum - 04-30-2011, 05:14 AM
Cannot modify header information - headers already sent - by El Forum - 04-30-2011, 05:34 AM
Cannot modify header information - headers already sent - by El Forum - 04-30-2011, 05:41 AM
Cannot modify header information - headers already sent - by El Forum - 04-30-2011, 05:51 AM
Cannot modify header information - headers already sent - by El Forum - 04-30-2011, 10:33 AM
Cannot modify header information - headers already sent - by El Forum - 05-01-2011, 10:23 PM



Theme © iAndrew 2016 - Forum software by © MyBB