Header file download

Source: Internet
Author: User
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 ');

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.