PHP实现简单的文件下载通用方法

2015-03-03 0 176
PHP实现简单的文件下载通用方法
function download_file($file){
	if(is_file($file)){
		$length = filesize($file);
		$type = mime_content_type($file);
		$showname =  ltrim(strrchr($file,'/'),'/');
		header("Content-Description: File Transfer");
		header('Content-type: ' . $type);
		header('Content-Length:' . $length);
		if (preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT'])) { //for IE
		 header('Content-Disposition: attachment; filename="' . rawurlencode($showname) . '"');
		} else {
		 header('Content-Disposition: attachment; filename="' . $showname . '"');
		}
		readfile($file);
		exit;
	} else {
	 exit('文件已被删除!');
	}
}

遇见资源网 php PHP实现简单的文件下载通用方法 http://www.ox520.com/7414.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务