View Code
Destfolder = $custDir; Custom uploaded file path $this->uppath = $custPath; $this->upname = $this->setname ($custName); $this->uptypes = $custTypes; $this->upmaxsize = $custMaxSize; $this->filefield = (string) $fileField; $this->time = time (); Initialization is used primarily to unify file names and directories}/** * Rename upload file, support Chinese name * * @param string $custName * @return Stri NG */Private Function SetName ($custName) {return! empty ($custName)? Iconv ("Utf-8", "GBK", $custName ): Date (' Ymdhis ', $this->time). Mt_rand (10, 99); /* * if ($custName = = ") {//If the file name is not set, a random file name is generated $name = Date (* ' Ymdhis ', $this->time). "_" . Mt_rand (10, 99). '.' . $this->ext; *//Determine if the file exists, do not allow duplicate file if (file_exists ($this->savepath. $name)) {* $name = Setsavename ($saveName);}} else {$name = $saveName;} * $this->savename = $name; } */} privatefunction SetPath () {return (Preg_match ('/\/$/', $this->uppath))? $this->uppath: $this->uppath. '/'; }/** * Create directory * * @param string $baseDir * @param string $destDir */priv Ate function mkdirs ($baseDir, $destDir) {$dirs = $baseDir; ! Is_dir ($dirs) && @mkdir ($dirs, 0777); It turns out that if the previous false is positive. The following statement executes if (! empty ($destDir)) {$destDirs = explode ('/', $destDir); foreach ($destDirs as $finalDir) {! empty ($finalDir) && $dirs. = $finalDir. '/'; ! Is_dir ($dirs) && @mkdir ($dirs, 0777); }} else {$dirs. = date (' Ymd ', $this->time). '/'; ! Is_dir ($dirs) && @mkdir ($dirs, 0777); } return $dirs; }/** * get suffix function * * @param string $fileName * @return Mixed */Private function G Etfileext ($filenaMe) {$extend = PathInfo ($filename); $this->chkfileext = $extend [' extension ']; }/** * Detect file Suffix function * * @return Boolean */Private Function Checkfileext () {if (In_array ( $this->chkfileext, $this->uptypes)) {//Here the program has a bug return TRUE; } else {$this->uperror = 1; return FALSE; }}/** * Detects maximum dimensions * * @return Boolean */Private Function checkfilemaxsize () {if ($thi S->chkfilesize > $this->upmaxsize) {$this->uperror = 2; return FALSE; } return TRUE; }/* * (Non-phpdoc) @see upload::fileupload () */Public Function fileUpload () {//single file, multiple file upload $ Keys = Array_keys ($_files [$this->filefield] [' name ']); foreach ($keys as $key) {if (! $_files [$this->filefield] [' name '] [$key]) continue; $sysError = $_files [$this->filEfield] [' ERROR '] [$key]; Switch ($sysError) {Case 1: $this->uperror = 3; Break Case 2: $this->uperror = 4; Break Case 3: $this->uperror = 5; Break Case 4: $this->uperror = 6; Break Case 5: $this->uperror = 7; Break } $this->chkfilename = Iconv ("Utf-8", "GBK", $_files [$this->filefield] [' name '] [$key]); The file name in the loop $this->chkfilesize = $_files [$this->filefield] [' size '] [$key]; The file size in the Loop $this->getfileext ($this->chkfilename); File type detection if (! $this->checkfileext ()) {return $this->errmsg (); Exit (); }//Over size if (! $this->cheCkfilemaxsize ()) {return $this->errmsg (); Exit (); if ($sysError = = 0 && is_uploaded_file ($_files [$this->filefield] [' tmp_name '] [$key]) { assembly file Name/* * $upFullPathName = $this->upname. $key. '.' . * $this->chkfileext; Duplicate if (file_exists ($upFullPathName *)) {$this->upfullname = $upFullPathName;} is not allowed */$this->upfullname = $this->upname. $key. '.' . $this->chkfileext; $this->upfullpathname = $this->mkdirs ($this->destfolder, $this->setpath ()). $this->upfullname; if (Move_uploaded_file ($_files [$this->filefield] [' tmp_name '] [$key], $this->upfullpathname)) { $this->sucssinfo [' name '] = $this->upfullpathname; $this->sucssinfo [' size '] = $this->chkfilesize; $this->sucssinfo [' info '] = ' file '. $this->upfullname. ' Upload success! '; }}} return $this->sucssinfo; }/* * (Non-phpdoc) @see upload::errmsg () */Public Function errmsg () {$ERRMSG = array ( 0 = ' File uploaded successfully! ', 1 = ' upload file '. $this->chkfilename. ' Type error, only support upload '. Implode (', ', $this->uptypes). ' File Type! ', 2 = ' upload file '. $this->chkfilename. ' Too big, maximum support '. Ceil ($this->upmaxsize/1024). ' KB file ', 3 = ' upload file '. $this->chkfilename. ' exceeds the value of the Upload_max_filesize option limit in php.ini. ', 4 = ' upload file '. $this->chkfilename. ' Size exceeds the value specified by the Max_file_size option in the HTML form! ', 5 = ' file '. $this->chkfilename. ' Only part is uploaded! ', 6 = ' no files were uploaded. ', 7 = ' File upload failed! ' ); if ($this->uperror = = 0) return false; else return $ERRMSG [$this->uperror]; }}
Publish your own definition of the upload class! Environment new and master shoot bricks!
# Custom Define page if (Access_has_global_level (Config_get (' Manage_site_threshold '))) { $t _menu_options[] = '' ) . Lang_get (' Custorm_list_link '). ''; $t _menu_options[] = "). Lang_get (' Ot_link '). ''; $t _menu_options[] = "). Lang_get (' Payment_link '). ''; } # Contact List if (!current_user_is_anonymous ()) { $t _menu_options[] = "). Lang_get (' Contact_list_link '). ' '; }