public function download(){
header("Content-Type:text/html;charset=UTF-8");
$name=$_GET['id'];
$file_dir = "./public/upload/file/";
$db=M('medias');
$list=$db->where('filename='.$_GET['id'])->select();
$shwoname=$list[0]['showname'];
$filename=$file_dir . $name;
import("@.ORG.Http");
$download=new Http();
$download->download($filename,$showname);
}
通过上面的代码能实现下载 但是下载下来后文件打不开,我是在本机上做的,源文件打的开,通过下载之后,就不行了。请问是为什么
header("Content-Type:text/html;charset=UTF-8");
$name=$_GET['id'];
$file_dir = "./public/upload/file/";
$db=M('medias');
$list=$db->where('filename='.$_GET['id'])->select();
$shwoname=$list[0]['showname'];
$filename=$file_dir . $name;
import("@.ORG.Http");
$download=new Http();
$download->download($filename,$showname);
}
通过上面的代码能实现下载 但是下载下来后文件打不开,我是在本机上做的,源文件打的开,通过下载之后,就不行了。请问是为什么
header("Content-Type:text/html;charset=UTF-8");
把这个去掉试试。
if(file_exists($filePath)) {
header('content-type:application/octet-stream');
header('accept-ranges: bytes');
header('content-length: '.filesize($filePath));
header('content-disposition:attachment;filename='.iconv('utf-8', 'gbk', $file['naming'].'.'.$file['extension']));
$fp = fopen($filePath, "r");
echo fread($fp, filesize($filePath));
fclose($fp);
}