There is a thumbnail feature but it feels incomplete, and there is a problem, continue to learn, in the future modified
<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 Protec Ted $filepath//File upload path protected $filemax//File Upload size protected $fileExt//File upload format protected $filename;//filename P rotected $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->filei nfo[' ERROR '] {Case 1: $this->fileerror= "Upload file size exceeds the maximum allowed for server upload, php.ini set upload_max_files
Value of the ize option limit ";
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)) {$t
his->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 is 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= to "repay maliciously";
return false;
return true;
The//File name prevents duplicate public function upname () {return MD5 (Microtime (TRUE), True) (UNIQID);
//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 "
Above this PHP image upload class instance code (added thumbnail) is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud-dwelling community.