How to download files in ZendFramework is as follows: My goal is to download files in a controller method. the downloaded files are not files in the local directory, it is a temporary data file generated in the controller method. Without ZF, PHP can set the header information for the browser to implement the download function. how can I implement the file download function in head Zend Framework?
For example, my goal is to download files in a controller method.
The downloaded file is not a file in the local directory, but a temporary data file generated in the controller method.
Without ZF, PHP can set the header information for the browser to download,
Header ("Content-type: text/plain ");
Header ("Accept-Ranges: bytes ");
Header ("Content-Disposition: attachment; filename =". $ filename );
Header ("Cache-Control: must-revalidate, post-check = 0, pre-check = 0 ");
Header ("Pragma: no-cache ");
Header ("Expires: 0 ");
Just like this, but in ZF, I put this code directly into a controller method, such as downloadController's downloadAction (). in the same way, I set the header information and print the data,
Print $ data;
But cannot be downloaded.
Could you tell me how experts can download files in zend framework, or does ZF have any built-in file downloads. After reading the manual, it seems that only files are uploaded. No Download
------ Solution --------------------
Layout and viewRenderer must be disabled.
Public function downloadAction (){
$ This-> _ helper-> getHelper ('layout ')-> disableLayout ();
$ This-> _ helper-> getHelper ('viewrenderer')-> setNoRender ();
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.