成人精品一区二区三区中文字幕-成人精品一区二区三区-成人精品一级毛片-成人精品亚洲-日本在线视频一区二区-日本在线视频免费

導(dǎo)航首頁 ? 技術(shù)教程 ? php利用header函數(shù)下載各種文件
全站頭部文字 我要出現(xiàn)在這里
php利用header函數(shù)下載各種文件 916 2024-01-27   

本文實(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 ();
}

?>

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持綠夏網(wǎng)。


主站蜘蛛池模板: 电影《皮埃里诺》免费观看| 《摧花狂魔》电影| 寄宿生韩剧全集观看| 萱草花合唱谱二声部完整版| 美女自拍偷拍| 长安长安朗诵报名入口| 爱情手册电影| 王思聪是谁| 祝妈妈生日快乐英文| 打男生军人光屁股的网站视频| 井冈山必去的三个景点| 头文字d里演员表| 四月一日| 公民的基本权利和义务教学设计| 酷刑| 子宫在肚子的哪个位置| 甜蜜监狱| 韶山行研学心得体会| 1769在线视频| 搜狐视频官网| 我的老婆是鬼王| bob hartman| 忍之国| 刘涛的21部毛片| hunger game| 日韩在线欧美| 李顺载| 少林问道演员表| 陕09j01图集| kaori主演电影在线观看| 2023大湾区音乐会节目单| cctv17节目表今天| 孤芳岚影| 快乐读书吧1-6年级推荐书目| 百家讲坛《两宋风云》| 爱在西元前简谱| 演员李崇霄的个人资料| 飞头魔女| 部队换季保养广播稿| 四大名著好词好句摘抄| 驱魔保安|

!!!站長長期在線接!!!

網(wǎng)站、小程序:定制開發(fā)/二次開發(fā)/仿制開發(fā)等

各種疑難雜癥解決/定制接口/定制采集等

站長微信:lxwl520520

站長QQ:1737366103