PHP头条
热点:

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


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

www.phpzy.comtrue/phprm/4063.htmlTechArticlethinkphp,http扩张类,download函数不能下载,只把文件的内容输出到页面 thinkphp,http扩展类,download函数不能下载,只把文件的内容输出到页面 开始我用,http扩展类想做1个文件下载的功...

相关文章

相关频道:

PHP之友评论

今天推荐