thinkphp,http扩展类,download函数不能上载,只把文件的内容输出到页面

WBOY
Release: 2016-06-13 12:54:30
Original
983 people have browsed it

thinkphp,http扩展类,download函数不能下载,只把文件的内容输出到页面
开始我用,http扩展类想做1个文件下载的功能
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);
}

}
}
文件并有没以附件形式下载,而是直接在页面输出文件的内容
然后,我不用他的扩展类写1个php页面,可以正常下载


$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;
}
?>
可以正常下载,但是我把这段代码粘贴到上面download函数,又出现http类的同样的结果,就是说,他不以附件形式下载,而是直接把文件的内容输出到页面
百思不得其解,跪求解释啊,为什么这样子,曾经用过http类的大神教教我吧,试了很久过不了这关


------解决方案--------------------
很显然你这个页面在输入Http头信息之前输出了其它内容。非常有可能是UTF-8的BOM
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!