码迷,mamicode.com
首页 > Web开发 > 详细

PHP文件下载

时间:2014-11-14 17:16:09      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:blog   io   os   sp   文件   数据   div   on   log   

function filedown($id, $type){
	$ziliao = M("ziliao");
	$data = $ziliao->where("id=%d and type=%d",$id,$type)->find();
	if(empty($data)){
		$this->downerror("数据异常!");
	}
	$filename = $data[‘name‘];
	$path = $data[‘path‘];
	$path = $_SERVER[‘DOCUMENT_ROOT‘] . $path;
	$path = iconv("UTF-8", "GB2312", $path);
	if(!is_file($path)){
		$this->downerror("文件不存在!");
	}
	
	$file = fopen($path,"r"); // 打开文件
	// 输入文件标签
	Header("Content-type: application/octet-stream");
	Header("Accept-Ranges: bytes");
	Header("Accept-Length: ".filesize($path));
	Header("Content-Disposition: attachment; filename=" . iconv("UTF-8", "GB2312", $filename));
	// 输出文件内容
	echo fread($file,filesize($path));
	fclose($file);
	exit();
}

  

PHP文件下载

标签:blog   io   os   sp   文件   数据   div   on   log   

原文地址:http://www.cnblogs.com/rnckty/p/4097439.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!