PHP implementation of the method of creating thumbnails from the upload file, _php tutorial

Source: Internet
Author: User
Tags imagejpeg

PHP implements the method of creating thumbnails from the upload file,


The examples in this article describe how PHP implements the creation of thumbnails from uploaded files. Share to everyone for your reference. The implementation method is as follows:

&LT;?PHPIF ($_request[' action ']== "add") {$userfile = $HTTP _post_files[' photo '] [' tmp_name ']; $userfile _name = $HTTP _ post_files[' photo ' [' name ']; $userfile _size = $HTTP _post_files[' photo ' [' size ']; $userfile _type = $HTTP _post_files[' Photo ' [' type '];///////////////////////////get-declare DIMENSIONS//$dimension = getimagesize ($userfile); $large _ width = $dimension [0]; GET PHOTO width$large_height = $dimension [1]; GET PHOTO height$small_width = 120; DECLARE THUMB width$small_height = 90;   DECLARE THUMB height///////////////////////////check SIZE//if ($userfile _size>102400) {$error = 1; $msg = "The photo is over 100kb. Please try again. ";} CHECK TYPE (IE and OTHERS)//if ($userfile _type= "Image/pjpeg") {if ($userfile _type!=    "Image/jpeg") {$error = 1;  $msg = "The photo must be JPG"; }}////////////////////////////////check width/height//if ($large _width!=600 or$large_height!=400) {$error =1; $msg = " The photo must be 600x400 pixels ";} ////////////CREATE thumb/upload THUMB and PHOTO///if ($error <>1) {$image = $userfile _name;  If you want-to-insert it to the database $pic = Imagecreatefromjpeg ($userfile);  $small = Imagecreatetruecolor ($small _width, $small _height);  Imagecopyresampled ($small, $pic, 0,0,0,0, $small _width, $small _height, $large _width, $large _height); if (imagejpeg ($small, "Path/to/folder/to/upload/thumb". $userfile _name) {$large = Imagecreatetruecolor ($large _  width, $large _height);    Imagecopyresampled ($large, $pic, 0,0,0,0, $large _width, $large _height, $large _width, $large _height); if (imagejpeg ($large, "Path/to/folder/to/upload/photo". $userfile _name)) {} else {$msg = "A problem has occured. P Lease try again. ";  $error = 1;} } else {$msg = "A problem has occured. Please try again. ";  $error = 1; }}/////////////////////////////////////////////////If Everything went right a photo (600x400) and///a thumb (120x90) wer e uploaded to the given folders}?><title>Create Thumb</title>

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/978381.html www.bkjia.com true http://www.bkjia.com/PHPjc/978381.html techarticle PHP Implementation of the method of creating thumbnails from the upload file, this article describes the PHP implementation of the method of creating thumbnails from the upload file. Share to everyone for your reference. The concrete implementation method is as follows: ...

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