You need to click the button to obtain information and download the content as a file. However, if you click "button", the new window is opened and the content is displayed, rather than the download window is displayed. The code is as follows: {code...} where GetDownLoadContentNew is used to format the content. No... click the button to obtain the information and download the content as a file.
However, if you click "button", the new window is opened and the content is displayed, rather than the download window is displayed.
The code is as follows:
$filename = $this->input->cookie('merchant_id');$timestamp = date("YmdHis",time());$filename .= $timestamp.'.'.$fileType;$title = mb_convert_encoding($title,'gbk','utf-8');header('Content-type: application/octet-stream');header('Cache-Control: must-revalidate, post-check=0, pre-check=0');header('Content-Transfer-Encoding: binary');header('Expires: 0');header('Content-Disposition: attachment; filename=' . $filename);echo $title;$ret = $this->download_model->QueryList($Req, $Resp);$content = $this->GetDownLoadContentNew($ret['bill_list'], $fileType);echo $content;
GetDownLoadContentNew is used to format the content.
I don't know where the problem is or where I didn't notice it? Thank you for your help. (FileType is csv or txt, which cannot be used to trigger download in different browsers)
Reply content:
You need to click the button to obtain information and download the content as a file.
However, if you click "button", the new window is opened and the content is displayed, rather than the download window is displayed.
The code is as follows:
$filename = $this->input->cookie('merchant_id');$timestamp = date("YmdHis",time());$filename .= $timestamp.'.'.$fileType;$title = mb_convert_encoding($title,'gbk','utf-8');header('Content-type: application/octet-stream');header('Cache-Control: must-revalidate, post-check=0, pre-check=0');header('Content-Transfer-Encoding: binary');header('Expires: 0');header('Content-Disposition: attachment; filename=' . $filename);echo $title;$ret = $this->download_model->QueryList($Req, $Resp);$content = $this->GetDownLoadContentNew($ret['bill_list'], $fileType);echo $content;
GetDownLoadContentNew is used to format the content.
I don't know where the problem is or where I didn't notice it? Thank you for your help. (FileType is csv or txt, which cannot be used to trigger download in different browsers)
/*** Force download file * @ param string $ file path */function force_download ($ file) {if (isset ($ file )) & (file_exists ($ file) {header ("Content-length :". filesize ($ file); header ('content-Type: application/octet-stream'); header ('content-Disposition: attachment; filename = "'. basename ($ file ). '"'); readfile ($ file);} else {echo" No file selected ";}// example force_download ('. /test.jpg ');