102400){...} "Method to create thumbnails from uploaded files."/> 102400){...} "Method to create thumbnails from uploaded files.">

Home>Article>Backend Development> How to implement file thumbnails in php

How to implement file thumbnails in php

藏色散人
藏色散人 Original
2021-07-14 09:52:38 2280browse

php method to implement file thumbnails: first create a PHP sample file; then pass "if ($_REQUEST['action']=="add"){...}if ($userfile_size>102400 ){...}" method to create thumbnails from uploaded files.

How to implement file thumbnails in php

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

How does php realize file thumbnails?

php method to create thumbnails from uploaded files

The example of this article describes the method of php to create thumbnails from uploaded files.

The specific implementation method is as follows:

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, 100)){ $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, 100)) {} else {$msg="A problem has occured. Please 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) were uploaded to the given folders } ?> create thumb
Select Photo:

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to implement file thumbnails in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn