代码如下
public function download()
{
$upload=M('upload');
$data=$upload->find($_GET['id']);
if(empty($data)){
header('HTTP/1.0 404 Not Found');
header('Location: .');
}else{
$path='./public/Uploads/'.$data['savename'];
header("Content-Type:".$data['type']);
header('Content-Disposition: attachment; filename="'.$data['name'].'"');
header('Content-Length:'.$data['size']);
ob_clean();
flush();
readfile($path);
}
}注意:
ob_clean();
flush();这个是关键哦。用了这两函数,搞定,图片正常打开,文字也不乱码。