Create Thumbnail And Upload image using PHP

Create Thumbnail And Upload image using PHP

Today, We want to share with you Create Thumbnail And Upload image using PHP.
In this post we will show you Create Thumbnail And Upload image using PHP, hear for Create Thumbnail And Upload image using PHP we will give you demo and example for implement.
In this post, we will learn about Create Thumbnail And Upload image using PHP with an example.

Simple Creating thumbnail images using PHP is a very common requirement for all the PHP web-developer.

You are The Many scripts use this to create a simple thumbnails(images) of uploaded images or any uploaded or stored images. In My POST for Create Thumbnail And Upload image using PHP

Also Read :  Simple PHP Shopping Cart

This PHP and HTML script used to this contains the source code of Upload image in your dir and create thumbnail using PHP.

HTML PART : index.php

First of all You create a simple Folder which upload this orignal or thumb image stored.

Folder Structure
-uploads
-uploads/thumbs/

Simple call function generate the thumbnails and orignal image stored.



<title>Upload Image And Create Thumbnail Using PHP - File Upload</title>


<div></div>
<form method="post" enctype="multipart/form-data">
	
    
</form>

<div align="center">
	<ul>
    	<li><img src="" alt="your Simple Programs for create thumbnails using PHP"></li>
    </ul>
</div>



PHP PART/script For Function of Upload Image And Create Thumbnail Using PHP – File Upload

<?php

function ngUpload($field_name = '', $target_folder = '', $sourcefilename = '', $thumb = FALSE, $thumb_folder = '', $imgthumb_width = '', $imgthumb_height = '')
{
	$target_path = $target_folder;
	$thumb_path = $thumb_folder;
	
	$filename_err = explode(".",$_FILES[$field_name]['name']);
	$filename_err_count = count($filename_err);
	$file_ext = $filename_err[$filename_err_count-1];
	if($sourcefilename != '')
	{
		$fileName = $sourcefilename.'.'.$file_ext;
	}
	else
	{
		$fileName = $_FILES[$field_name]['name'];
	}
	
	$thumbimg_upload = $target_path.basename($fileName);
	
	if(move_uploaded_file($_FILES[$field_name]['tmp_name'],$thumbimg_upload))
	{
		if($thumb == TRUE)
		{
			$thumbnail = $thumb_path.$fileName;
			list($width,$height) = getimagesize($thumbimg_upload);
			$thumb_create = imagecreatetruecolor($imgthumb_width,$imgthumb_height);
			switch($file_ext){
				case 'jpg':
					$source = imagecreatefromjpeg($thumbimg_upload);
					break;
				case 'jpeg':
					$source = imagecreatefromjpeg($thumbimg_upload);
					break;
				case 'png':
					$source = imagecreatefrompng($thumbimg_upload);
					break;
				case 'gif':
					$source = imagecreatefromgif($thumbimg_upload);
					break;
				default:
					$source = imagecreatefromjpeg($thumbimg_upload);
			}
			imagecopyresized($thumb_create,$source,0,0,0,0,$imgthumb_width,$imgthumb_height,$width,$height);
			switch($file_ext){
				case 'jpg' || 'jpeg':
					imagejpeg($thumb_create,$thumbnail,100);
					break;
				case 'png':
					imagepng($thumb_create,$thumbnail,100);
					break;
				case 'gif':
					imagegif($thumb_create,$thumbnail,100);
					break;
				default:
					imagejpeg($thumb_create,$thumbnail,100);
			}
		}

		return $fileName;
	}
	else
	{
		return false;
	}
}


if(!empty($_FILES['image']['name'])){
	
	$img_uploads = ngUpload('image','uploads/','',TRUE,'uploads/thumbs/','200','160');
	
	$small_thumb = 'uploads/thumbs/'.$img_uploads;
	
	$respnosemsg = $img_uploads?"<span style='color:#D4C5DD'>Your Image thumbnail easy way 2 have been created successfully. plz contact Pakainfo.com</span>":"<span style='color:#FDADA5'>Some error your PHP source occurred, please steps by execue try again.</span>";
	
}else{

	$small_thumb = '';
	$respnosemsg = '';
}
?>

View Demo

Also Read :  Vuejs Filter Currency Round to 2 decimal places

We hope you get an idea about Create Thumbnail And Upload image using PHP
We would like to have feedback on my Information blog .
Your valuable any feedback, Good question, Inspirational Quotes, or Motivational comments about this article are always welcome.
If you liked this post, Please don’t forget to share this as Well as Like FaceBook Page.

We hope This Post can help you…….Good Luck!.

Searches related to : Create Thumbnail And Upload image using PHP

  • php create thumbnail from image url
  • how to generate thumbnail image
  • php thumbnail script example
  • php create thumbnail on the fly
  • create thumbnail image in php while uploading video
  • image upload and generate thumbnail using ajax in php
  • php thumbnail generator
  • how to create thumbnail image from video in laravel

Recommended For You.

DataTables Column Search Server side processing
Today, We want to share with you DataTables Column Search Server side processing in PHP.In this post we will show

Add a Comment

Your email address will not be published. Required fields are marked *