/*======================================================<BR> <p style="color:transparent">。本文来源gao!%daima.com搞$代*!码网1</p><cite>搞代gaodaima码</cite>$FileName 为文件名称,必传<BR> $FilePath 为文件路径.选填,可以为相对路径或者绝对路径<BR> 路径只能由英文跟数据组成,不能带有中文<BR> ======================================================*/</P><P><?php <BR> header("Content-type: text/html;charset=utf-8");<BR> if(strlen($FileName)<=3){echo "下载失败:你所以下载的文件信息有误";return;}<BR> $FileName=iconv("utf-8","gb2312",$FileName);//进行文件名格式转换,以防中文乱码<BR> //开始判断路径<BR> if(!is_null($FilePath)&&strlen($FilePath)>1){<br><br> if(substr($FilePath,0,1)=='/'){//判断是否为绝对路径<br><br> $FilePath=$_SERVER['DOCUMENT_ROOT'].$FilePath;<br><br> }<BR> if(substr($FilePath,-1)!="/"){//检查最后是否为 / 结尾<br><br> $FilePath=$FilePath.'/';<br><br> }<BR> if(is_numeric(strpos($FilePath,":\"))){//检查是否为绝对路径<br><br> $FilePath=str_replace("/","\",$FilePath);<br><br> }<BR> }elseif(strlen($FilePath)==1&&$FilePath!="/"){<br><br> $FilePath=$FilePath."/";<br><br> }else{<br><br> $FilePath="";<br><br> }<BR> if(!file_exists($FilePath.$FileName)){<br><br> echo"下载失败:所要下载的文件未找到";return;<br><br> }<BR> /*================================================<BR> 发送下载相关的头部信息<BR> =================================================*/<br><br> header("Content-type: application/octet-stream");<br><br> header("Accept-Ranges: bytes");//按照字节大小返回<br><br> header("Accept-Length: $FileSize");//返回文件大小<br><br> header("Content-Disposition: attachment; filename=".$FileName);//这里客户端的弹出对话框,对应的文件名<br><br> /*================================================<BR> 开始下载相关<BR> =================================================*/ <BR>$FileSize=filesize($FilePath.$FileName);<br><br> $File=fopen($FilePath.$FileName,"r");//打开文件<br><br> $FileBuff=512;<br><br> while($FileSize>=0){<br><br> $FileSize-=$FileBuff;<br><br> echo fread($File,$FileBuff);<br><br> }<br><br> fclose($File);<BR> }<BR>?><BR>