我有一个像这样的数组
$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 ) );我需要做的是
1)下载csv
2)之后将$ data返回给控制器 如果我在返回代码之后使用退出,则下载csv文件但会话不会打印。 如果我从代码会话消息打印中删除退出,但csv不下载
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.
我有示例代码
In controller
function downloadErrorCSV() {$data=$this->tankmodel->downloadcsv(); $this->session->set_flashdata('successAddBulkTank','success'); redirect('mypage');}在模型中我有
{some code of model} and $data='sucess'{code of download csv} and then return $data;现在如果我在csv下载脚本csv之后放置它会被下载并且如果删除退出;它不下载csv我需要两者 下载 csv和 显示成功消息。
答案 0 :(得分:2)
您必须将下载和保存数据的代码分开。
我相信您不必在服务器上保存错误文件。并使用javascript代码下载该文件。
请勿使用以下代码立即下载文件 $ data = $ this-> tankmodel-> downloadcsv(); 。首先将其保存在服务器上,然后在显示消息后再下载。
在服务器上保存Excel文件:Here
下载此文件可以使用两种方式:
location.href = 'http://sitefullpath/yourfilename';
[iframe src="yourfilename"][/iframe]
希望这会有所帮助。