<?php
if(!defined('IN_MICECMS')){header("HTTP/1.0 404 Not Found");die();}
/*
*下载功能
*/

function download($fileadd, $filename) {
	if(ereg("^(http|ftp)",$fileadd))
	{
		$file = @fopen($fileadd,"r");   
		if(!$file){   
			echo  '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><Script language="JavaScript">alert(\'文件不存在\');history.go(-1);</Script>'; 
		}else{   
		  Header("Content-type:   application/octet-stream");   
		  Header("Content-Disposition:   attachment;filename=".$filename);   
		  while(!feof($file)){   
			echo fread($file,5000);   
		  }   
		  fclose($file);
		}
	}else{
		if (!is_file($fileadd)){
			echo  '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><Script language="JavaScript">alert(\'文件不存在\');history.go(-1);</Script>'; 
		}else{
			$file = fopen($fileadd,"r");   //   打开文件
			Header("Content-type:   application/octet-stream");   
			Header("Accept-Ranges:   bytes");   
			Header("Accept-Length:   ".filesize($fileadd));   
			Header("Content-Disposition:   attachment;filename=".$filename);   
			echo   fread($file,filesize($fileadd));   
			fclose($file);
		}
	}
	exit;
}

?>