PHP File Download Filter class
SetFilter ($fileFilter); $this->setdebug ($isDebug); $this->setfiletype ();} function DownloadFile ($filename) {$this->filename= $filename, if ($this->filecheck ()) {$FN = basename ($this FileName); Ob_end_clean (); @set_time_limit ($this->limittime); header (' cache-control:max-age=31536000 '); header ( ' Expires: '. Gmdate (' d, D M Y h:i:s ', Time () +31536000). ' GMT '), header (' Content-encoding:none '), header (' Content-length: '. FileSize ($this->filename)); Header (' Content-disposition:attachment; Filename= '. $fn); header (' Content-type: '. $this->minetype); ReadFile ($this->filename); return true;} Else{return false;}} function FileCheck () {$fileName = $this->filename;if (file_exists ($fileName)) {$fileType = Strtolower (Array_pop ( Explode (".", $fileName)), if (!in_array ($fileType, $this->filter)) {$this->errormsg.= sprintf ("%s can ' t download! ", $fileName), if ($this->debug) exit (sprintf ("%s can ' t download! ", $fileName)); return false;} else {if (function_exists ("Mime_content_type")) {$this->minetype= Mime_content_type ($fileName);} if (Empty ($this->minetype)) {if (Isset ($this->xlq_filetype[$fileType])) {$this->minetype= $this->xlq_ filetype[$fileType];}} if (!empty ($this->minetype)) {return true;} else {$this->errormsg.= "Can ' t get file type!"; if ($this->debug) exit ("Can ' t get file type!"); return false;}}} else {$this->errormsg.= sprintf ("%s not exists!", $fileName), if ($this->debug) exit (sprintf ("%s isn ' t exists!", $fileName)); return 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 ']= "Javascrīpt/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 ']= "image/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 ']= "Image/x-xbitmap"; $this->xlq_filetype[' xwd ']= "Image/x-xwindowdump"; $this->xlq_filetype[' ief ']= "Image/ief"; $this->xlq_filetype[' tif ']= "Image/tiff"; $this->xlq_filetype[' TIFF ']= "Image/tiff"; $this->xlq_filetype[' PNM ']= "Image/x-portable-anymap"; $this->xlq_filetype[' PGM ']= "Image/x-portable-graymap"; $this->xlq_filetype[' RGB ']= "Image/x-rgb"; $this->xlq_filetype[' xpm ']= "Image/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 ']= "video/mpeg"; $this->xlq_filetype[' mpe ']= "video/mpeg"; $this->xlq_filetype[' avi ']= "Video/x-msvideo"; $this->xlq_filetype[' qt ']= "video/quicktime"; $this->xlq_filetype[' mov ']= "video/quicktime"; $this->xlq_filetype[' Moov ']= "Video/quicktime"; $this->xlq_filetype[' movie ']= "Video/x-sgi-movie"; $this->xlq_filetype[' au ']= "audio/basic"; $this->xlq_filetype[' snd ']= "Audio/basic"; $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";} function SetFilter ($fileFilter) {if (empty ($fileFilter)) return; $this->filter= explode (",", Strtolower ($ FileFilter));} function Setdebug ($debug) {$this->debug= $debug;} function Setlimittime ($limittime) {$this->limittime= $limittime;} function GetFileName ($filename) {return $this->filename;} function Geterrormsgs () {return $this->errormsg;} function __destruct () {$this->errormsg= ';}}? >
//?? Examples of Use:
? $filename = ' Data.rar ';
? $download =new Download (' php,exe,html ', false);
? if (! $download->downloadfile ($filename, ' data '))
? {
????????? echo $download->geterrormsg ();
? }