欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php實(shí)現(xiàn)文件下載(支持中文文名)

 更新時(shí)間:2013年12月04日 12:05:02   作者:  
這個(gè)下載實(shí)例結(jié)合header函數(shù)與while fread函數(shù)把文件分?jǐn)嘧x出來(lái)然后再發(fā)送到客戶(hù)端了,支持中文文名,算得上一個(gè)標(biāo)準(zhǔn)的文件下載實(shí)例

復(fù)制代碼 代碼如下:

 /*======================================================
  $FileName 為文件名稱(chēng),必傳
  $FilePath 為文件路徑.選填,可以為相對(duì)路徑或者絕對(duì)路徑
      路徑只能由英文跟數(shù)據(jù)組成,不能帶有中文
 ======================================================*/

<?php
 header("Content-type: text/html;charset=utf-8");
 if(strlen($FileName)<=3){echo "下載失?。耗闼韵螺d的文件信息有誤";return;}
 $FileName=iconv("utf-8","gb2312",$FileName);//進(jìn)行文件名格式轉(zhuǎn)換,以防中文亂碼
 //開(kāi)始判斷路徑
 if(!is_null($FilePath)&&strlen($FilePath)>1){

  if(substr($FilePath,0,1)=='/'){//判斷是否為絕對(duì)路徑

   $FilePath=$_SERVER['DOCUMENT_ROOT'].$FilePath;

    }
  if(substr($FilePath,-1)!="/"){//檢查最后是否為 / 結(jié)尾

   $FilePath=$FilePath.'/';

    }
  if(is_numeric(strpos($FilePath,":\"))){//檢查是否為絕對(duì)路徑

   $FilePath=str_replace("/","\",$FilePath);

    }
   }elseif(strlen($FilePath)==1&&$FilePath!="/"){

    $FilePath=$FilePath."/";

   }else{

    $FilePath="";

  }
  if(!file_exists($FilePath.$FileName)){

   echo"下載失?。核螺d的文件未找到";return;

   }
  /*================================================
   發(fā)送下載相關(guān)的頭部信息
  =================================================*/

  header("Content-type: application/octet-stream");

  header("Accept-Ranges: bytes");//按照字節(jié)大小返回

  header("Accept-Length: $FileSize");//返回文件大小

  header("Content-Disposition: attachment; filename=".$FileName);//這里客戶(hù)端的彈出對(duì)話框,對(duì)應(yīng)的文件名

  /*================================================
   開(kāi)始下載相關(guān)
  =================================================*/
$FileSize=filesize($FilePath.$FileName);

  $File=fopen($FilePath.$FileName,"r");//打開(kāi)文件

  $FileBuff=512;

  while($FileSize>=0){

   $FileSize-=$FileBuff;

   echo fread($File,$FileBuff);

  }

  fclose($File);
 }
?>


相關(guān)文章

最新評(píng)論