PHP upload picture class display thumbnail function _php instance

Source: Internet
Author: User

There is a thumbnail feature but it feels incomplete, and there is a problem, continue to learn, in the future modify the next

<form action= "<?php $_server[' php_self ';?>" enctype= "Multipart/form-data" method= "POST" ><input type = "text" name= "name"/><input type= "file" name= "file"/><input type= "Submission" name= ' submit ' value= ' submitted ' >
</form> <?php/** * Created by Phpstorm. * User:administrator * DATE:2016/6/28 * time:21:04/class upload{protected $fileMine;//File upload type protected $filepath;
File upload path protected $filemax//File Upload size protected $fileExt//File upload format protected $filename;//filename protected $fileerror;//File Error setting Protected $fileflag//file detection protected $fileinfo; FILES protected $ext;
File extension protected $path; File Upload public function __construct ($filename = "File", $filemax =20000000, $filepath = "./uploads", $fileflag =true,$ Fileext=array (' jpg ', ' exe '), $fileMine =array (' image/jpeg ')) {$this->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 judgement Public Function Uperror () {if ($this->fileinfo[' ERROR ']>0) {switch ($this->fileinfo[' error ') {Case 1:
$this->fileerror= "Upload file size exceeds the maximum server allowed upload, php.ini set the upload_max_filesize option limit value";
Break
Case 2: $this->fileerror= "The upload file size exceeds the value specified by the hidden field max_file_size option in the HTML form";
Break
Case 3: $this->fileerror= "file part uploaded";
Break
Case 4: $this->fileerror= "did not choose 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 does 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 wrong ";
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= "incorrect file format"; RetuRN false;
return true; }//Detect file path Public function Uppath () {if (!file_exists ($this->filepath)) {mkdir ($this->filepath,0777,true);}// Detect file Size Public function upsize () {$max = $this->fileinfo[' size '; if ($max > $this->filemax) {$this->fileerror
= "File too large";
return false;
return true; //detects whether the file is HTTP Public function Uppost () {if (!is_uploaded_file ($this->fileinfo[' Tmp_name ')) {$this->fileerror=
"Maliciously repaid";
return false;
return true; }//filename prevents duplicate public function upname () {return MD5 (Uniqid (TRUE), true);}//Picture thumbnail public function smallimg ($x =100 , $y =100) {$imgAtt =getimagesize ($this->path);//image wide, high, type $imgWidth = $imgAtt [0]; $imgHeight = $IMGATT [1]; $imgext =$
IMGATT[2]; Equal-ratio column scaling if (($x/$imgWidth) > ($y/$imgHeight)) {$BL = $y/$imgHeight;} else{$BL = $x/$imgWidth;} $x =floor ($imgWidth * $bl);
$y =floor ($imgHeight * $bl) after zooming;
$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->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 ("<b>" $this->fileerror. "
</b> ");
}} <?php header ("Content-type:imagejpeg");
Header ("Content-type:text/html;charset=utf-8");
Require ' list.php ';
$u =new upload ();
$a = $u->uploads ();
$c = $u->smallimg ();
echo " <! DOCTYPE html>  

The above is a small series to introduce the PHP upload picture class display thumbnail function of the relevant knowledge, hope to help everyone, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.