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:
<?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