<?php/*** file Upload class * @author lijiamin* @time 2017-02-17* @email 1195989301@qq.com*/class upload{private $allowExt = Array ( ' gif ', ' jpg ', ' jpeg ', ' BMP ', ' png ', ' SWF ');//limit file upload suffix private $maxSize = 1;//limit maximum file upload 1m/*** get file information * @param str $flag The identity of the uploaded file * @return An array of */public function GetInfo ($flag) {return $_files[$flag] for the upload file of arr;} /*** gets the suffix of the file * @param str $filename file name * @return str file extension */public function Getext ($filename) {return pathinfo ($filename, PA thinfo_extension);} /*** detect the upload file is legitimate * @param str $filename filename * @return bool file extension is legal */private function Checkext ($filename) {$ext = $this->g ETEXT ($filename); return In_array ($ext, $this->allowext);} /*** detect if file size exceeds limit * @param int size File size * @return bool file size exceeds limit */public function Checksize ($size) {return $size < $this ->maxsize * 1024 * 1024;} /*** random filename * @param int $len The length of the random file name * @return str random string */public function Randname ($len =6) {return substr (Str_shuffle (' ABC defghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ234565789 '), 0, $len);} /*** create the path to the file uploaded * @retuRN str File Upload path */Public Function Createdir () {//upload file path $dir = './upload/'. Date (' y/m/d ', Time ());//Determine if the folder exists, does not exist the new if (Is_ Dir ($dir) | | mkdir ($dir, 0777,true)) {return $dir;}} /*** File Upload * @param str $flag File Upload identifier * @return Array returns the upload file name, save path */public function UploadFile ($flag) {if ($_files[$flag] [' Name '] = = = ' | | $_files[$flag] [' ERROR ']!== 0) {echo "did not upload the file"; return;} $info = $this->getinfo ($flag), if (! $this->checkext ($info [' name '])) {echo "Unsupported file type"; return;} if (! $this->checksize ($info [' size ']) {echo "File size exceeds limit"; return;} $filename = $this->randname (). '. '. $this->getext ($info [' name ']), $dir = $this->createdir (), if (!move_uploaded_file ($info [' tmp_name '), $dir. '/'. $ FileName) {echo "File upload failed";} Else{return Array (' filename ' = = $filename, ' dir ' = = $dir);}}? >