PHP文件下载

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();
}

  

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。