Thinkphp and http Extension class. the download function cannot be downloaded. it only outputs the file content to the page.

Source: Internet
Author: User
Thinkphp, http Extension class, the download function cannot be downloaded. I only need to output the file content to the page and use it. the http Extension class wants to provide the function class & nbsp; indexAction & nbsp; extends & nbsp; Action & nbsp; {public & nbsp; functi thinkphp, http Extension class. the download function cannot be downloaded and only outputs the file content to the page.
I started to use the http Extension class to download one file.
Class IndexAction extends Action {

Public function download ()
{

$ File_dir = "D:/wamp/www/test/uploads /";
$ Name = 'aa.rar ';

$ Filename = $ file_dir. $ name;
If (! Empty ($ name )){
Import ("ORG. Net. Http ");
$ Download = new Http ();
$ Download-> download ($ filename, $ name );
}

}
}
The file is not downloaded as an attachment, but directly output the file content on the page.
Then, I don't need his extension class to write a php page and can download it normally.


$ File = 'd:/wamp/www/test/uploads/admin.rar ';
 
If (file_exists ($ file )){
Header ('content-Description: File Transfer ');
Header ('content-Type: application/octet-stream ');
Header ('content-Disposition: attachment; filename = '. basename ($ file ));
Header ('content-Transfer-Encoding: binary ');
Header ('expires: 0 ');
Header ('cache-Control: must-revalidate, post-check = 0, pre-check = 0 ');
Header ('pragma: public ');
Header ('content-Length: '. filesize ($ file ));
Ob_clean ();
Flush ();
Readfile ($ file );
Exit;
}
?>
It can be downloaded normally, but I paste this code into the download function, and the same result of the http class appears, that is, it is not downloaded as an attachment, instead, the file content is directly output to the page.
I cannot explain it. I beg for an explanation. why? I have used a great http class to teach me how to solve this problem for a long time.
------ Solution --------------------
Obviously, this page outputs other content before entering the Http header information. Probably the BOM of the UTF-8

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.