最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

php利用header函數(shù)下載各種文件

 更新時(shí)間:2016年08月24日 09:33:02   作者:※WYF※  
這篇文章主要為大家詳細(xì)介紹了php利用header函數(shù)下載各種文件的代碼,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了php header函數(shù)下載文件實(shí)現(xiàn)代碼,供大家參考,具體內(nèi)容如下

http://www.php.net/manual/en/function.readfile.php

<?php
/**
* 下載文件
* header函數(shù)
*
*/


dl_file($_GET ['filename']);

function dl_file($file)
{
 $file = ".//images//" . $file;
 //First, see if the file exists
 
 if (! is_file ( $file ))
 {
  die ( "<b>404 File not found!</b>" );
 }
 
 // Gather relevent info about file
 $len = filesize ( $file );
 $filename = basename ( $file );
 $file_extension = strtolower ( substr ( strrchr ( $filename, "." ), 1 ) );
 
 // This will set the Content-Type to the appropriate setting for the file
 switch ($file_extension)
 {
  case "pdf" :
   $ctype = "application/pdf";
   break;
  case "exe" :
   $ctype = "application/octet-stream";
   break;
  case "zip" :
   $ctype = "application/zip";
   break;
  case "doc" :
   $ctype = "application/msword";
   break;
  case "xls" :
   $ctype = "application/vnd.ms-excel";
   break;
  case "ppt" :
   $ctype = "application/vnd.ms-powerpoint";
   break;
  case "gif" :
   $ctype = "image/gif";
   break;
  case "png" :
   $ctype = "image/png";
   break;
  case "jpeg" :
  case "jpg" :
   $ctype = "image/jpg";
   break;
  case "mp3" :
   $ctype = "audio/mpeg";
   break;
  case "wav" :
   $ctype = "audio/x-wav";
   break;
  case "mpeg" :
  case "mpg" :
  case "mpe" :
   $ctype = "video/mpeg";
   break;
  case "mov" :
   $ctype = "video/quicktime";
   break;
  case "avi" :
   $ctype = "video/x-msvideo";
   break;
  
  // The following are for extensions that shouldn't be downloaded
  // (sensitive stuff, like php files)
  case "php" :
  case "htm" :
  case "html" :
  case "txt" :
   die ( "<b>Cannot be used for " . $file_extension . " files!</b>" );
   break;
  
  default :
   $ctype = "application/force-download";
 }
 
 
 $file_temp = fopen ( $file, "r" );
 
 
 // Begin writing headers
 header ( "Pragma: public" );
 header ( "Expires: 0" );
 header ( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
 header ( "Cache-Control: public" );
 header ( "Content-Description: File Transfer" );
 // Use the switch-generated Content-Type
 header ( "Content-Type: $ctype" );
 // Force the download
 $header = "Content-Disposition: attachment; filename=" . $filename . ";";
 header ( $header );
 header ( "Content-Transfer-Encoding: binary" );
 header ( "Content-Length: " . $len );
 
 
 //@readfile ( $file );
 echo fread ( $file_temp, filesize ( $file ) );
 fclose ( $file_temp );
 
 exit ();
}

?>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

天祝| 海城市| 扬中市| 大石桥市| 温泉县| 沂南县| 无棣县| 常德市| 鹤壁市| 建平县| 精河县| 阳东县| 长葛市| 双辽市| 平昌县| 新兴县| 方山县| 波密县| 澄江县| 峡江县| 汪清县| 乌拉特前旗| 通化县| 乐业县| 唐山市| 内乡县| 双流县| 琼中| 聊城市| 奇台县| 盖州市| 梁山县| 西贡区| 梨树县| 舞钢市| 九寨沟县| 沙河市| 瑞安市| 溆浦县| 镇沅| 吉隆县|