좋은 PHP 파일 다운로드 클래스

WBOY
풀어 주다: 2016-07-25 08:58:46
원래의
1268명이 탐색했습니다.
  1. /**

  2. ** PHP 파일 다운로드 클래스
  3. **예:
  4. $download=new download('php,exe,html',false);
  5. if(!$download->downloadfile($ 파일 이름))
  6. {
  7. echo $download->geterrormsg();
  8. }
  9. * by bbs.it-home.org
  10. */
  11. 수업 다운로드{
  12. var $debug=true ;
  13. var $errormsg='';
  14. var $Filter=array();
  15. var $filename='';
  16. var $mineType='text/plain';
  17. var $ xlq_filetype=array();

  18. 함수 다운로드($fileFilter='',$isdebug=true)

  19. {
  20. $this->setFilter($fileFilter);
  21. $this->setdebug($isdebug);
  22. $this->setfiletype();
  23. }

  24. function setFilter($fileFilter)

  25. {
  26. if(empty($fileFilter)) return ;
  27. $this->Filter=explode(',',strtolower($fileFilter));
  28. }
  29. function setdebug($debug )
  30. {
  31. $this->debug=$debug;
  32. }

  33. function setfilename($filename)

  34. {
  35. $this- >filename=$filename;
  36. }

  37. 함수 다운로드 파일($filename)

  38. {
  39. $this->setfilename($filename);
  40. if($this->filecheck())
  41. {
  42. $fn = array_pop(explod( '/', strtr( $this->filename, '\', '/' ) ) );
  43. header( "Pragma: public" );
  44. header( "Expires: 0" ); // 만료 시간 설정
  45. header( "Cache-Component: must-revalidate, post-check=0, pre-check=0" );
  46. header( "Content-type:".$this-> mineType );
  47. header( "콘텐츠 길이: " . filesize( $this->filename ) );
  48. header( "콘텐츠 처리: attachment; filename="$fn"" );
  49. 헤더( '콘텐츠 전송 인코딩: 바이너리' );
  50. readfile( $this->filename );
  51. true를 반환합니다.
  52. }else
  53. {
  54. false를 반환합니다.
  55. }
  56. }
  57. function geterrormsg()
  58. {
  59. return $this->errormsg;
  60. }

  61. function filecheck()

  62. {
  63. $filename=$this->filename;
  64. if(file_exists($filename))
  65. {
  66. $filetype=strtolower(array_pop(explode('.',$filename))) ;
  67. if(in_array($filetype,$this->Filter))
  68. {
  69. $this->errormsg.=$filename.'不允许下载!';
  70. if($ this->debug)exit($filename.'不允许下载!') ;
  71. false 반환;
  72. }else
  73. {
  74. if ( function_exists( "mime_content_type" ) )
  75. {
  76. $this->mineType = mime_content_type( $filename );
  77. }
  78. if(empty($this->mineType))
  79. {
  80. if( isset($this->xlq_filetype[$filetype]) ) $this->mineType = $ this->xlq_filetype[$filetype];
  81. }
  82. if(!empty($this->mineType))
  83. return true;
  84. else
  85. {
  86. $this- >errormsg.=''.$filename.' 파일 형식을 얻는 동안 오류가 발생했거나 미리 결정된 파일 형식이 존재하지 않습니다.';
  87. if($this->debug) exit('파일을 얻는 동안 오류가 발생했습니다. type');
  88. return false;
  89. }
  90. }
  91. }else
  92. {
  93. $this->errormsg.=$filename.'존재하지 않습니다!';
  94. if($this ->debug) exit($filename.'존재하지 않습니다!') ;
  95. false를 반환합니다.
  96. }
  97. }
  98. function setfiletype()

  99. {
  100. $this->xlq_filetype['chm']='application/octet-stream';
  101. $this-> ;xlq_filetype['ppt']='application/vnd.ms-powerpoint';
  102. $this->xlq_filetype['xls']='application/vnd.ms-excel';
  103. $this-> ;xlq_filetype['doc']='application/msword';
  104. $this->xlq_filetype['exe']='application/octet-stream';
  105. $this->xlq_filetype['rar' ]='application/octet-stream';
  106. $this->xlq_filetype['js']="javascript/js";
  107. $this->xlq_filetype['css']="text/css ";
  108. $this->xlq_filetype['hqx']="application/mac-binhex40";
  109. $this->xlq_filetype['bin']="application/octet-stream";
  110. $this->xlq_filetype['oda']="application/oda";
  111. $this->xlq_filetype['pdf']="application/pdf";
  112. $this->xlq_filetype[ 'ai']="application/postsrcipt";
  113. $this->xlq_filetype['eps']="application/postsrcipt";
  114. $this->xlq_filetype['es']="application/ postrcipt";
  115. $this->xlq_filetype['rtf']="application/rtf";
  116. $this->xlq_filetype['mif']="application/x-mif";
  117. $this->xlq_filetype['csh']="application/x-csh";
  118. $this->xlq_filetype['dvi']="application/x-dvi";
  119. $this-> ;xlq_filetype['hdf']="application/x-hdf";
  120. $this->xlq_filetype['nc']="application/x-netcdf";
  121. $this->xlq_filetype[' cdf']="application/x-netcdf";
  122. $this->xlq_filetype['latex']="application/x-latex";
  123. $this->xlq_filetype['ts']= "application/x-troll-ts";
  124. $this->xlq_filetype['src']="application/x-wais-source";
  125. $this->xlq_filetype['zip']= "application/zip";
  126. $this->xlq_filetype['bcpio']="application/x-bcpio";
  127. $this->xlq_filetype['cpio']="application/x-cpio ";
  128. $this->xlq_filetype['gtar']="application/x-gtar";
  129. $this->xlq_filetype['shar']="application/x-shar";
  130. $this->xlq_filetype['sv4cpio']="application/x-sv4cpio";
  131. $this->xlq_filetype['sv4crc']="application/x-sv4crc";
  132. $this- >xlq_filetype['tar']="application/x-tar";
  133. $this->xlq_filetype['ustar']="application/x-ustar";
  134. $this->xlq_filetype[ 'man']="application/x-troff-man";
  135. $this->xlq_filetype['sh']="application/x-sh";
  136. $this->xlq_filetype['tcl ']="application/x-tcl";
  137. $this->xlq_filetype['tex']="application/x-tex";
  138. $this->xlq_filetype['texi']=" application/x-texinfo";
  139. $this->xlq_filetype['texinfo']="application/x-texinfo";
  140. $this->xlq_filetype['t']="application/x- troff";
  141. $this->xlq_filetype['tr']="application/x-troff";
  142. $this->xlq_filetype['roff']="application/x-troff";
  143. $this->xlq_filetype['shar']="application/x-shar";
  144. $this->xlq_filetype['me']="application/x-troll-me";
  145. $this->xlq_filetype['ts']="application/x-troll-ts";
  146. $this->xlq_filetype['gif']="image/gif";
  147. $this-> ;xlq_filetype['jpeg']="image/pjpeg";
  148. $this->xlq_filetype['jpg']="image/pjpeg";
  149. $this->xlq_filetype['jpe']= "image/pjpeg";
  150. $this->xlq_filetype['ras']="image/x-cmu-raster";
  151. $this->xlq_filetype['pbm']="이미지/x -portable-bitmap";
  152. $this->xlq_filetype['ppm']="image/x-portable-pixmap";
  153. $this->xlq_filetype['xbm']="이미지/x -xbitmap";
  154. $this->xlq_filetype['xwd']="image/x-xwindowdump";
  155. $this->xlq_filetype['ief']="image/ief";
  156. $this->xlq_filetype['tif']="이미지/tiff";
  157. $this->xlq_filetype['tiff']="이미지/tiff";
  158. $this->xlq_filetype[ 'pnm']="image/x-portable-anymap";
  159. $this->xlq_filetype['pgm']="image/x-portable-graymap";
  160. $this->xlq_filetype[ 'rgb']="image/x-rgb";
  161. $this->xlq_filetype['xpm']="image/x-xpixmap";
  162. $this->xlq_filetype['txt'] ="text/plain";
  163. $this->xlq_filetype['c']="text/plain";
  164. $this->xlq_filetype['cc']="text/plain";
  165. $this->xlq_filetype['h']="text/plain";
  166. $this->xlq_filetype['html']="text/html";
  167. $this->xlq_filetype ['htm']="text/html";
  168. $this->xlq_filetype['htl']="text/html";
  169. $this->xlq_filetype['rtx']="text /richtext";
  170. $this->xlq_filetype['etx']="text/x-setext";
  171. $this->xlq_filetype['tsv']="text/tab-separated-values ";
  172. $this->xlq_filetype['mpeg']="비디오/mpeg";
  173. $this->xlq_filetype['mpg']="video/mpeg";
  174. $this->xlq_filetype[' mpe']="비디오/mpeg";
  175. $this->xlq_filetype['avi']="video/x-msvideo";
  176. $this->xlq_filetype['qt']="비디오 /quicktime";
  177. $this->xlq_filetype['mov']="video/quicktime";
  178. $this->xlq_filetype['moov']="video/quicktime";
  179. $ this->xlq_filetype['movie']="video/x-sgi-movie";
  180. $this->xlq_filetype['au']="audio/basic";
  181. $this-> xlq_filetype['snd']="audio/basic";
  182. $this->xlq_filetype['wav']="audio/x-wav";
  183. $this->xlq_filetype['aif'] ="audio/x-aiff";
  184. $this->xlq_filetype['aiff']="audio/x-aiff";
  185. $this->xlq_filetype['aifc']="오디오/ x-aiff";
  186. $this->xlq_filetype['swf']="application/x-shockwave-flash";
  187. }
  188. }
  189. ?>

复代码


원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
최신 이슈
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!