Thinkphp,http extension class, the download function cannot be uploaded, only the contents of the file are output to the page

Source: Internet
Author: User
Thinkphp,http extension class, download function can not download, only the contents of the file output to the page
To start with, the HTTP extension class wants to do 1 file download functions
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);
}

}
}
File is not downloaded as an attachment, but directly in the page output file content
Then, I do not have his extension class to write 1 PHP pages, you can download the normal


$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
}
?>
Can be downloaded normally, but I paste this code into the above download function, and the same result of the HTTP class, that is, he does not download as an attachment, but directly the contents of the file output to the page
Think of its solution, kneeling beg to explain Ah, why this, once used the HTTP class of the Great God taught me, tried for a long time not to pass this


------Solution--------------------
It's obvious that you have this page output something else before you enter the HTTP header information. It's very likely the UTF-8 BOM.
  • 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.