1

I have an array like that

$csvDownload=Array
    (
        [0] => Array
            (
                [serial] => Serial
                [volume] => Tanksize
                [manufacturer] => Manufacturer
                [manufacturerDate] => manufacturerDate
                [warehouse] => Warehousename
                [pickLocation] => PickupLocation
                [pickDate] => pickDate
                [CompanyName] => Company
                [nationalBoard] => nationalBoard
            )
        [1] => Array
            (
                [serial] => 20001
                [volume] => 120H
                [manufacturer] => Atlas
                [manufacturerDate] => 2013
                [warehouse] => WAREHOUSE1
                [pickLocation] => kanpur
                [pickDate] => 2/25/2014
                [CompanyName] => WIM
                [nationalBoard] => he
            )
        );
what i need to do is

1)download csv

2)after then return $data to controller if i use Exit after the code before return it works download the csv file but session do not print. if i remove exit from code session message print but csv do not download

Please help what i am doing wrong or any way to solve this..!
I need both session flash as well as download the csv file.

I have sample code

In controller
function downloadErrorCSV()
    {$data=$this->tankmodel->downloadcsv();    $this->session->set_flashdata('successAddBulkTank','success');
    redirect('mypage');}
In model i have
{some code of model} and $data='sucess'{code of download csv} and then return $data;
Now if i place exit after csv download script csv it get downloaded and if remove exit;it do not download the csv I need both download csv and show success message as well.
Deepak
  • 523
  • 4
  • 24

1 Answers1

2

You have to separate your code of downloading and saving data.

I believe you don't have to save error file at server. and use javascript code to download that file.

don't download file immediately using this code $data=$this->tankmodel->downloadcsv();. save it first at server then download it later after showing message.

Saving Excel File at server: Here

Downloading of this file you can use two ways:

  • Javasctipt location.href = 'http://sitefullpath/yourfilename';
  • iframe: [iframe src="yourfilename"][/iframe]

Hope this will help.

Manwal
  • 23,450
  • 12
  • 63
  • 93
  • "thanks" but if i do so it takes too much time to execute i have 1000s of data to be uploaded.to uploading the same data twice is not better idea. – Deepak May 21 '14 at 07:02
  • @DeepakSharma i think you don't understand what i said i am not asking it two time one time is enough to save Failed data and you can download it whenever you want. – Manwal May 21 '14 at 07:19
  • hy @deepak manwal it works for me like a charm thanks a lot.! – Deepak May 21 '14 at 13:22