>  기사  >  백엔드 개발  >  패치 파일 PHP 파일 다운로드 클래스

패치 파일 PHP 파일 다운로드 클래스

WBOY
WBOY원래의
2016-07-29 08:35:281280검색

코드 복사 코드는 다음과 같습니다.

//=========================================== =======   
//   사용 사례:   
// $download=new download('php,exe,html',false);   
//  if(!$download->downloadfile($filename))   
//  {   
//    echo $download->geterrormsg();   
//  }         
//====================================== =============   
클래스 다운로드{   
  var $debug=true;   
  var $errormsg='';   
  var $Filter=array();   
  var $filename='';   
  var $mineType='text/plain';   
  var $xlq_filetype=array();   
  함수 다운로드($fileFilter='',$isdebug=true)   
  {   
    $this->setFilter($fileFilter);   
        $this->setdebug($isdebug);           
        $this->setfiletype();   
  }   
  function setFilter($fileFilter)   
  {   
    if(empty($fileFilter)) return ;   
        $this->Filter=explode(',',strtolower($fileFilter));   
  }   
  함수 setdebug($debug)   
  {   
    $this->debug=$debug;   
  }   
  함수 setfilename($filename)   
  {   
    $this->filename=$filename;   
  }   
  함수 다운로드 파일($filename)   
  {   
    $this->setfilename($filename);   
    if($this->filecheck())   
        {   
         $fn = array_pop( explode( '/', strtr( $this->filename, '\', '/' ) ) );   
          헤더( "Pragma: 공개" );   
      헤더( "만료: 0" ); // 만료 시간 설정   
      header( "Cache-Component: must-revalidate, post-check=0, pre-check=0" );   
          헤더( "Content-type:".$this->mineType );   
      header( "콘텐츠 길이: " . filesize( $this->filename ) );   
      헤더( "Content-Disposition: attachment; filename="$fn"" );   
      헤더( '콘텐츠 전송-인코딩: 바이너리' );   
      readfile( $this->filename );   
      true를 반환합니다.   
        }else   
        {   
        false를 반환합니다.   
        }   
  }   
  함수 geterrormsg()   
  {   
    return $this->errormsg;   
  }   
  함수 filecheck()   
  {   
    $filename=$this->filename;   
        if(file_exists($filename))   
        {   
           $filetype=strtolower(array_pop(explode('.',$filename)));   
          if(in_array($filetype,$this->Filter))   
          {   
            $this->errormsg.=$filename.'不允许下载!';   
                if($this->debug) exit($filename.'不允许下载!') ;   
                false를 반환합니다.   
           }else   
           {   
            if ( function_exists( "mime_content_type" ) )   
                {   
           $this->mineType = mime_content_type( $filename );   
         }   
                if(empty($this->mineType))   
               {
                   if(isset($this-& gt;xlq_filetype[$filetype]) )  $this->mineType = $ this->xlq_filetype[$filetype];   
                }   
                if(!empty($this->mineType))   
                  return true;   
                else   
                {   
                 $this->errormsg.='获取'.$filename.'文件类型时候发生错误,或者不存在预定文件类型内';   
                      if($this->debug) exit('获取文件类型 Out错');   
                       false를 반환합니다.   
               }   
           }    
        }else   
        {
         $this->errormsg.=$filename.'不存지금!';   
          if($this->debug) exit($filename.'不存재!') ;   
          false를 반환합니다.   
        }   
  }   
  function setfiletype()   
  {   
    $this->xlq_filetype['chm']='application/octet-stream';   
    $this->xlq_filetype['ppt']='application/vnd.ms-powerpoint';   
    $this->xlq_filetype['xls']='application/vnd.ms-excel';   
    $this->xlq_filetype['doc']='application/msword';   
    $this->xlq_filetype['exe']='application/octet-stream';   
    $this->xlq_filetype['rar']='application/octet-stream';   
    $this->xlq_filetype['js']="javascript/js";   
    $this->xlq_filetype['css']="text/css";   
    $this->xlq_filetype['hqx']="application/mac-binhex40";   
    $this->xlq_filetype['bin']="application/octet-stream";   
    $this->xlq_filetype['oda']="application/oda";   
    $this->xlq_filetype['pdf']="application/pdf";   
    $this->xlq_filetype['ai']="application/postsrcipt";   
    $this->xlq_filetype['eps']="application/postsrcipt";   
    $this->xlq_filetype['es']="application/postsrcipt";   
    $this->xlq_filetype['rtf']="application/rtf";   
    $this->xlq_filetype['mif']="application/x-mif";   
    $this->xlq_filetype['csh']="application/x-csh";   
    $this->xlq_filetype['dvi']="application/x-dvi";   
    $this->xlq_filetype['hdf']="application/x-hdf";   
    $this->xlq_filetype['nc']="application/x-netcdf";   
    $this->xlq_filetype['cdf']="application/x-netcdf";   
    $this->xlq_filetype['latex']="application/x-latex";   
    $this->xlq_filetype['ts']="application/x-troll-ts";   
    $this->xlq_filetype['src']="application/x-wais-source";   
    $this->xlq_filetype['zip']="application/zip";   
    $this->xlq_filetype['bcpio']="application/x-bcpio";   
    $this->xlq_filetype['cpio']="application/x-cpio";   
    $this->xlq_filetype['gtar']="application/x-gtar";   
    $this->xlq_filetype['shar']="application/x-shar";   
    $this->xlq_filetype['sv4cpio']="application/x-sv4cpio";   
    $this->xlq_filetype['sv4crc']="application/x-sv4crc";   
    $this->xlq_filetype['tar']="application/x-tar";   
    $this->xlq_filetype['ustar']="application/x-ustar";   
    $this->xlq_filetype['man']="application/x-troff-man";   
    $this->xlq_filetype['sh']="application/x-sh";   
    $this->xlq_filetype['tcl']="application/x-tcl";   
    $this->xlq_filetype['tex']="application/x-tex";   
    $this->xlq_filetype['texi']="application/x-texinfo";   
    $this->xlq_filetype['texinfo']="application/x-texinfo";   
    $this->xlq_filetype['t']="application/x-troff";   
    $this->xlq_filetype['tr']="application/x-troff";   
    $this->xlq_filetype['roff']="application/x-troff";   
    $this->xlq_filetype['shar']="application/x-shar";   
    $this->xlq_filetype['me']="application/x-troll-me";   
    $this->xlq_filetype['ts']="application/x-troll-ts";   
    $this->xlq_filetype['gif']="image/gif";   
    $this->xlq_filetype['jpeg']="이미지/pjpeg";   
    $this->xlq_filetype['jpg']="image/pjpeg";   
    $this->xlq_filetype['jpe']="image/pjpeg";   
    $this->xlq_filetype['ras']="image/x-cmu-raster";   
    $this->xlq_filetype['pbm']="image/x-portable-bitmap";   
    $this->xlq_filetype['ppm']="image/x-portable-pixmap";   
    $this->xlq_filetype['xbm']="이미지/x-xbitmap";   
    $this->xlq_filetype['xwd']="image/x-xwindowdump";   
    $this->xlq_filetype['ief']="이미지/ief";   
    $this->xlq_filetype['tif']="이미지/tiff";   
    $this->xlq_filetype['tiff']="이미지/tiff";   
    $this->xlq_filetype['pnm']="image/x-portable-anymap";   
    $this->xlq_filetype['pgm']="image/x-portable-graymap";   
    $this->xlq_filetype['rgb']="이미지/x-rgb";   
    $this->xlq_filetype['xpm']="이미지/x-xpixmap";   
    $this->xlq_filetype['txt']="text/plain";   
    $this->xlq_filetype['c']="text/plain";   
    $this->xlq_filetype['cc']="text/plain";   
    $this->xlq_filetype['h']="text/plain";   
    $this->xlq_filetype['html']="text/html";   
    $this->xlq_filetype['htm']="text/html";   
    $this->xlq_filetype['htl']="text/html";   
    $this->xlq_filetype['rtx']="text/richtext";   
    $this->xlq_filetype['etx']="text/x-setext";   
    $this->xlq_filetype['tsv']="text/tab-separated-values";   
    $this->xlq_filetype['mpeg']="video/mpeg";   
    $this->xlq_filetype['mpg']="비디오/mpeg";   
    $this->xlq_filetype['mpe']="비디오/mpeg";   
    $this->xlq_filetype['avi']="video/x-msvideo";   
    $this->xlq_filetype['qt']="동영상/quicktime";   
    $this->xlq_filetype['mov']="동영상/quicktime";   
    $this->xlq_filetype['moov']="비디오/quicktime";   
    $this->xlq_filetype['movie']="video/x-sgi-movie";   
    $this->xlq_filetype['au']="오디오/기본";   
    $this->xlq_filetype['snd']="오디오/기본";   
    $this->xlq_filetype['wav']="audio/x-wav";   
    $this->xlq_filetype['aif']="audio/x-aiff";   
    $this->xlq_filetype['aiff']="audio/x-aiff";   
    $this->xlq_filetype['aifc']="audio/x-aiff";   
    $this->xlq_filetype['swf']="application/x-shockwave-flash";   
  }   
}   
?> 

以上就介绍了patch文件 PHP文件下载类, 包括了patch文件方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.