-
-
/*---------------- - * $FileName is the file name, must be passed
- * $FilePath is the file path .Optional, it can be a relative path or an absolute path
- * @The path can only be composed of English and data, not Chinese
- * @Edited by: bbs.it-home.org
- --------- ---------*/
-
- header("Content-type: text/html;charset=utf-8");
- if(strlen($FileName)<=3){echo "Download failed : The file information you downloaded is incorrect";return;}
- $FileName=iconv("utf-8","gb2312",$FileName);//Convert the file name format to prevent Chinese garbled characters
- //Start Determine the path
- if(!is_null($FilePath)&&strlen($FilePath)>1){
- if(substr($FilePath,0,1)=='/'){//Determine whether it is an absolute path
- $FilePath =$_SERVER['DOCUMENT_ROOT'].$FilePath;
- }
- if(substr($FilePath,-1)!="/"){//Check whether the end is /
- $FilePath=$FilePath.'/' ;
- }
- if(is_numeric(strpos($FilePath,":"))){//Check whether it is an absolute path
- $FilePath=str_replace("/","",$FilePath);
- }
- }elseif( strlen($FilePath)==1&&$FilePath!="/"){
- $FilePath=$FilePath."/";
- }else{
- $FilePath="";
- }
- if(!file_exists($FilePath. $FileName)){
- echo "Download failed: The file to be downloaded was not found"; return;
- }
- /*-------------
- Send download related header information
- -- -----------=*/
- header("Content-type: application/octet-stream");
- header("Accept-Ranges: bytes");//Return according to byte size
- header("Accept-Length: $FileSize");//Return the file size
- header("Content-Disposition: attachment; filename=".$FileName);//The client's pop-up dialog box here, the corresponding file name< /p>
/*-------------
- Start downloading related
- -------------=*/
- $FileSize=filesize( $FilePath.$FileName);
- $File=fopen($FilePath.$FileName,"r");//Open the file
- $FileBuff=512;
- while($FileSize>=0){
- $FileSize-=$ FileBuff;
- echo fread($File,$FileBuff);
- }
- fclose($File);
- }
- ?>
-
Copy code
|