PHP image upload class (with thumbnails added), _ PHP Tutorial

Source: Internet
Author: User
PHP image upload class (with thumbnails added ),. For the image upload class of PHP (with thumbnails added), the thumbnail function is not comprehensive, and there is a problem. continue to learn. will you modify the formaction in the future? Php $ _ SERVER [PHP _ PHP image upload class (with thumbnails added ),

The thumbnail function is not comprehensive, and it is a problem. continue to learn and modify it later.

 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 );} // public function UpError () {if ($ this-> fileinfo ['error']> 0) {switch ($ this-> fileinfo ['error']) {case 1: $ this-> fileerror = "the size of the uploaded file exceeds the maximum size allowed by the server. php. set upload_max_filesize in ini to select Item limit value "; break; case 2: $ this-> fileerror =" the size of the uploaded file exceeds the value specified by the MAX_FILE_SIZE field in the HTML form "; break; case 3: $ this-> fileerror = "partially uploaded files"; break; case 4: $ this-> fileerror = "no file selected"; break; case 5: $ this-> fileerror = "temporary directory not 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 ;} // check the file type public func Tion UpMine () {if (! In_array ($ this-> fileinfo ['type'], $ this-> fileMine) {$ this-> error = "the file upload type is incorrect"; return false ;} return true;} // check the 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 incorrect"; return false;} return true ;} // check the file path public function UpPath () {if (! File_exists ($ this-> filepath) {mkdir ($ this-> filepath, 0777, true) ;}// check the file size public function UpSize () {$ max = $ this-> fileinfo ['size']; if ($ max> $ this-> filemax) {$ this-> fileerror = "The file is too large "; return false;} return true;} // check whether the file is HTTP public function UpPost () {if (! Is_uploaded_file ($ this-> fileinfo ['tmp _ name']) {$ this-> fileerror = "malicious repayment"; return false;} return true ;} // file name prevent repeated public function Upname () {return md5 (uniqid (microtime (true), true);} // image 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]; // proportional column scaling if ($ x/$ imgWidth)> ($ y/$ imgHeight) {$ bl = $ y/$ imgHeight;} else {$ bl = $ x/$ imgWidth ;} $ x = floor ($ imgWidth * $ bl); // after scaling, $ y = floor ($ imgHeight * $ bl); $ images = imagecreatetruecolor ($ x, $ y ); $ big = imagecreatefromjpeg ($ this-> path); imagecopyresized ($ images, $ big, 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 double-pass 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 ("". $ This-> fileerror ."") ;}}?>

  

 uploads();  $c=$u->Smallimg();echo "";echo "";?>

  

 
 Examples
 
 
     

  

Thumbnail (with thumbnail added). The thumbnail function is not comprehensive, and it is a bit problematic. continue to learn. in the future, modify 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.