PHP operation method of uploading files and pictures

Source: Internet
Author: User
Tags imagejpeg
This article mainly introduces the PHP implementation from the upload file to create thumbnails of the method, involving PHP operation upload file and image manipulation skills, with a certain reference value, the need for friends can refer to the next

The examples in this article describe how PHP implements the creation of thumbnails from uploaded files. 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}?>

Summary : The above is the entire content of this article, I hope to be able to help you learn.

Related recommendations:

PHP implementation of the press release system

PHP operation image Size modification, add watermark, generate verification code, output and save

PHP Query the function of songs through the Sina Library search interface

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.