PHP implementation File upload php file upload plugin php file upload plugin php ftp upload text

Source: Internet
Author: User
Tags http post php file upload upload php
The tool classes are as follows:

 MaxSize = $maxSize; $this->allowmime = $allowMime; $this->allowext = $allowExt; $this->uploadpath = $uploadPath; $this->imgflag = $imgFlag; $this->init ();} Private Function init () {$this->fileinfo = array (); foreach ($_files as $k = = $v) {$this->fileinfo = $v;} if (!empty ($this->fileinfo)) {$this->ext = Strtolower (pathinfo ($this->fileinfo[' name '], pathinfo_extension ));}} /*** Upload file * @return If the upload fails then return false, if the upload succeeds, then the return path */public function UploadFile () {if (! $this->checkerror () | |! $this- >checksize () | | ! $this->checkhttppost () | | ! $this->checktrueimg ()) {return false;} if (!empty ($this->allowext) &&! $this->checkext ()) {return false;} if (!empty ($this->allowmime) &&! $this->checkmime ()) {return false;} $this->checkuploadpath (); $this->uniname = $this->getuniname (); $this->destination = $this Uploadpath. '/' . $this->uniname. '.' . $this->ext;if (! @move_uploaded_file ($this->fileinfo[' tmp_name '), $this->d estination)) {return false;} return $this->destination;} /*** get error message */public function GetError () {return $this->error;} /*** detect error Uploading file * @return boolean*/private function checkerror () {if (Empty ($this->fileinfo)) {$this->error = ' Error on file '; $this->code = 1001;return false;} if ($this->fileinfo[' error '] = = 0) {return true;} Switch ($this->fileinfo[' ERROR ']) {Case 1: $this->error = ' exceeds the value of the upload_max_filesize option in the PHP configuration file '; $this->code = 1002;break;case 2: $this->error = ' exceeds the value set in the form max_file_size '; $this->code = 1003;break;case 3: $this->error = ' File part is uploaded '; $this->code = 1004;break;case 4: $this->error = ' No upload file selected '; $this->code = 1005;break;case 6: $this Error = ' No temporary directory found '; $this->code = 1006;break;case 7: $this->error = ' File not writable '; $this->code = 1007;break;case 8:$ This->error = ' Due to PHP extension interrupt file Upload '; $this->code = 1008;break;} return false;} /*** Detecting the size of the uploaded file * @return boolean*/private function checksize () {if ($this->fileinfo[' size '] > $this->maxsize) {$this->error = ' upload file is too large '; $this->code = 1009;return false;} return true;} /*** Detection extension * @return boolean*/private function Checkext () {if (!in_array ($this->ext, $this->allowext)) {$this Error = ' disallowed extension '; $this->code = 1010;return false;} return true;} /*** detection File type * @return boolean*/private function allowmime () {if (!in_array ($this->fileinfo[' type '], $this- Allowmime) {$this->error = ' disallowed file type '; $this->code = 1011;return false;} return true;} /*** detection is true picture * @return Boolean*/private function checktrueimg () {if ($this->imgflag) {if (! @getimagesize ($this fileinfo[' Tmp_name ')) {$this->error = ' Not a real picture '; $this->code = 1012;return false;} return true;} return true;} /*** detects if an HTTP post is uploaded * @return boolean*/private function checkhttppost () {if (!is_uploaded_file ($this->fileinfo [' Tmp_name '])) {$this->error = ' file not uploaded via HTTP post '; $this->code = 1013;return false;} return true;} /*** detection directory does not exist, create */private function Checkuploadpath () {if (!file_exists ($this->uploadpath) {mkdir ($this->uploadpath, 0777, True);}} /*** produces a unique string * @return String*/private function getuniname () {return MD5 (Uniqid (Microtime (True), true));}} ?>

Here's how to use it:

 
  File Upload

 
  UploadFile (); if (! ( $destination = = = False) {echo "$destination";} echo $uploadHelper->geterror ();?>

The above describes the PHP implementation of file upload, including file Upload, PHP content, I hope that the PHP tutorial interested in a friend helpful.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.