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.