PHP Image upload Class (added thumbnail), _php tutorial

Source: Internet
Author: User

PHP Image upload Class (added thumbnail),


have thumbnail function but feel not comprehensive, and a little problem, continue to study, future changes under

 Filename= $filename;        $this->fileinfo=$_files[$this->filename];        $this->filemax= $filemax;        $this->filepath= $filepath;        $this->fileflag= $fileflag;        $this->fileext= $fileExt;        $this->filemine= $fileMine;    Var_dump ($this->filename); }//Error judgment Public Function Uperror () {if ($this->fileinfo[' ERROR ']>0) {switch ($this-&gt (fileinfo[' ERROR ']) {Case 1: $this->fileerror= "Upload file size exceeds the maximum allowed uploads by the server                        Value, set the value of the Upload_max_filesize option limit in php.ini ";                    Break                        Case 2: $this->fileerror= "The upload file size exceeds the value specified by the Hidden fields max_file_size option in the HTML form";                    Break                        Case 3: $this->fileerror= "file part was uploaded";                    Break                        Case 4: $this->fileerror= "no option to upload files";                    Break Case 5: $this->fileerror= "No temporary directory found";                    Break                        Case 6: $this->fileerror= "file write Failed";                    Break                        Case 7: $this->fileerror= "php file upload extension not open";                    Break                        Case 8: $this->fileerror= "";                Break            } return false;    } return true;            }//Detect file Type Public Function Upmine () {if (!in_array ($this->fileinfo[' type '], $this->filemine)) {            $this->error= "File upload type is not correct";        return false;    } return true;        }//Detect file Format Public Function Upext () {$this->ext=pathinfo ($this->fileinfo[' name '],pathinfo_extension);        Var_dump ($ext);            if (!in_array ($this->ext, $this->fileext)) {$this->fileerror= "file format is incorrect";        return false; } RetuRN true; }//Detect file path Public function Uppath () {if (!file_exists ($this->filepath)) {mkdir ($this->filepat        H,0777,true);        }}//Detect file Size public function upsize () {$max = $this->fileinfo[' size ');            if ($max > $this->filemax) {$this->fileerror= "file is too large";        return false;    } return true; }//Detect if the file is HTTP Public function Uppost () {if (!is_uploaded_file ($this->fileinfo[' Tmp_name ')) {$t            his->fileerror= "ill-paid";        return false;    } return true;    }//File name prevents duplicate public function upname () {return MD5 (Uniqid (Microtime (True), true));        }//Picture thumbnail public function smallimg ($x =100, $y =100) {$imgAtt =getimagesize ($this->path);        Image width, height, type $imgWidth = $imgAtt [0];        $imgHeight = $imgAtt [1];        $imgext = $imgAtt [2];        Scaling if (($x/$imgWidth) > ($y/$imgHeight)) {$BL = $y/$imgHeight;           }else{ $BL = $x/$imgWidth;  } $x =floor ($imgWidth * $bl);        After zooming $y =floor ($imgHeight * $bl);        $images =imagecreatetruecolor ($x, $y);        $big =imagecreatefromjpeg ($this->path);        Imagecopyresized ($images, $big, 0,0,0,0, $x, $y, $imgWidth, $imgWidth);                Switch ($imgext) {Case 1: $imageout =imagecreatefromgif ($this->path);            Break                Case 2: $imageout =imagecreatefromjpeg ($this->path);            Break                Case 3: $imageout =imagecreatefromgif ($this->path);        Break    } $im =imagejpeg ($images, $this->path); }//File dual public Function uploads () {if ($this->uperror () && $this->upmine () && $this-&gt ;            Upext () && $this->upsize () && $this->uppost ()) {$this->uppath ();            $names = $this->upname (); $this->path= $this->filepath. ' /'. $names. '.            $this->ext;if (Move_uploaded_file ($this->fileinfo[' tmp_name '), $this->path) {return $this->path;            }else{$this->fileerror= "upload failed"; }}else{Exit ("". $this->fileerror.""); }}}?>

  

 
  Uploads ();  $c = $u->smallimg (); echo ""; echo ";? >

  

 
  
 
  Examples
 
  
 
  
 
      

  

http://www.bkjia.com/PHPjc/1138633.html www.bkjia.com true http://www.bkjia.com/PHPjc/1138633.html techarticle PHP Image upload Class (add thumbnail), have thumbnail function but feel not comprehensive, and a little problem, continue to learn, in the future to modify the next form action= "? php $_server[' Php_ ...

  • 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.