php强制下载文件函数
时间:2021-07-05 09:21:30|栏目:PHP代码|点击: 次
本文实例为大家分享了php强制下载文件函数,供大家参考,具体内容如下
public function down()
{
$id = $this->_get('id');
$M = M("downloads");
$data=$M->where("id=$id and status=1")->find();
!$data && exit;
$filename = iconv('UTF-8','GBK',$data['filename']);
$savename = $data['savename'];
$myfile = $data[url] ? $data[url] : 'Uploads/file/'.$savename;
if(file_exists($myfile)){
$M->where("id=$id")->setInc('downloads');
$file = @ fopen($myfile, "r");
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=" .$filename );
while (!feof($file)) {
echo fread($file, 50000);
}
fclose($file);
exit;
}else{
echo '文件不存在!';
}
}
栏 目:PHP代码
下一篇:php.ini-dist 和 php.ini-recommended 的区别介绍(方便开发与安全的朋友)
本文标题:php强制下载文件函数
本文地址:http://www.codeinn.net/misctech/152934.html






