PHP Resize Image Upload Example

Today, We want to share with you PHP Resize Image Upload Example.In this post we will show you php upload image generate thumbnail example, hear for How to upload and resize image in PHP ? we will give you demo and example for implement.In this post, we will learn about PHP image upload and resize it before uploading tutorial with an example.

PHP Resize Image Upload Example

There are the Following The simple About Resize Image Upload Full Information With Example and source code.

As I will cover this Post with live Working example to develop Upload and Resize an Image with PHP, so the Image Upload and Resize it using PHP for this example is following below.


<!DOCTYPE html>
	<title>PHP Image resize to upload -</title>
<div class="container dsp">
	<form action="do_submit.php" method="post" enctype="multipart/form-data">
		<input type="file" name="image" /> 
		<input type="submit" name="submit" value="Submit" />


if(isset($_POST["submit"])) {
    if(is_array($_FILES)) {
        $file = $_FILES['image']['tmp_name']; 
        $img_src_data = getimagesize($file);
        $fl_new_name = time();
        $uploded_path = "upload/";
        $ext = pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION);
        $imageType = $img_src_data[2];
        switch ($imageType) {
            case IMAGETYPE_PNG:
                $img_main_id = imagecreatefrompng($file); 
                $t_layer_data = imageResize($img_main_id,$img_src_data[0],$img_src_data[1]);
                imagepng($t_layer_data,$uploded_path. $fl_new_name. "_thump.". $ext);
            case IMAGETYPE_GIF:
                $img_main_id = imagecreatefromgif($file); 
                $t_layer_data = imageResize($img_main_id,$img_src_data[0],$img_src_data[1]);
                imagegif($t_layer_data,$uploded_path. $fl_new_name. "_thump.". $ext);
            case IMAGETYPE_JPEG:
                $img_main_id = imagecreatefromjpeg($file); 
                $t_layer_data = imageResize($img_main_id,$img_src_data[0],$img_src_data[1]);
                imagejpeg($t_layer_data,$uploded_path. $fl_new_name. "_thump.". $ext);
                echo "YOUR Invalid Image type.";
        move_uploaded_file($file, $uploded_path. $fl_new_name. ".". $ext);
        echo "Image Resize Successfully.";
function imageResize($img_main_id,$width,$height) {
    $targetWidth =200;
    $targetHeight =200;
    imagecopyresampled($t_layer_data,$img_main_id,0,0,0,0,$targetWidth,$targetHeight, $width,$height);
    return $t_layer_data;

Web Programming Tutorials Example with Demo

Read :


You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about simple Resize Image Upload using PHP.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Related FAQ

Here are some more FAQ related to this Article:

  1.   PHP Image Resize Tutorials
  2.   jquery Compress or resize Image File Size before Uploading PHP Code
  3.   Laravel 5.8 Datatables Server Side Processing
  4.   Create Dynamic Web Pages using PHP-MYSQL
  5.   Laravel dynamic breadcrumbs with links
  6.   ERROR 1118 (42000) Row size too large
  7.   Laravel Framework version Types
  8.   Vuejs nested components
  9.   PHP Image Resize, Crop, Thumbnail, Watermark
  10.   PHP Laravel 6 Session-Based Flash Message Example