File Upload – Auto Resize Compress-Reduce image using PHP

File Upload – Auto Resize Compress-Reduce image using PHP

Today, We want to share with you File Upload – Auto Resize Compress-Reduce image using PHP.
In this post we will show you File Upload – Auto Resize Compress-Reduce image using PHP, hear for File Upload – Auto Resize Compress-Reduce image using PHP we will give you demo and example for implement.
In this post, we will learn about File Upload – Auto Resize Compress-Reduce image using PHP with an example.

In this Post,Going to show little bit advance of Auto Resize Compress-Reduce image uploading your server or folder.Means of Resize Image While Uploading with PHP

Also Read :  Automatically Timeout-Logout Destroy Session inactivity Using PHP

First of all we create on images Folder in Root directory based.nad then home-main.php create a file in this place.It was based on php script to simple Auto Resize Compress-Reduce image upload functionality.

home-main.php

This script resize your uploaded an Image into two 186px and 76px.new Take a look at simple $newwidth and newheight created you have to modify size values.(Image Like as a jpg,png,etc.)

Here in this POST,is a very quick and Fast easy to source code, simple script to do it:

<form action="do-mst.php" method="POST" enctype="multipart/form-data">
		<fieldset>
			
			<div class="form-group">
				<label>Apps Title :</label>
				<input class="form-control" name="stitle" placeholder="Apps Title" type="text" value="<?php echo $sti['stvalue']; 
				?>">
			</div>
			
			<div class="form-group">
				<label>Apps Image(Logo)</label>
				<input type="file" class="file" name="Appslfile" value="<?php 
				echo $stimg['stvalue'];
				?>"/>
				<br/>
				<img src="../images/<?php 
					echo $stimg['stvalue'];
				?>" height="76px" width="168px" class="img-rounded"/>
				
			</div>
			
		</fieldset>
		<div>
			<input type="submit" id="Appsmst" name="Appsmst"  class="btn btn-primary" value="Update"/>
		
		</div>
</form>

do-mst.php

<?php
if(isset($_POST['Appsmst']))
{

	$stitle=$_POST['stitle'];
	$ck_img_name=$_FILES["Appslfile"]["name"];	
	$target_dir = "../images/";
	$target_file = $target_dir . basename($_FILES["Appslfile"]["name"]);
	if($_POST['stitle']);
	{
		$stitle=$db->query("UPDATE `setting` SET `stvalue`='$stitle' WHERE `stid`=1");
	}
	
	if(move_uploaded_file($_FILES["Appslfile"]["tmp_name"], $target_file)) 
	{
		$stitle=$db->query("UPDATE `setting` SET `stvalue`='$ck_img_name' WHERE `stid`=2");
		
		$orig_image = imagecreatefromjpeg($target_file);
		$temp_img_info = getimagesize($target_file); 
		$width_orig  = $temp_img_info[0]; // current orignal width as found in image file
		$height_orig = $temp_img_info[1]; // current orignal height as found in image file
		$width = 186; // Simple new image user custom width
		$height = 76; // simple new image user custom height
		$des_img_logo = imagecreatetruecolor($width, $height);
		imagecopyresampled($des_img_logo, $orig_image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
		
		imagejpeg($des_img_logo, $target_file, 100);
		
	}
	header("Location: home-main.php");
}
?>

: Example :

Also Read :  How to Post Into Facebook Group with PHP using Graph API

We hope you get an idea about File Upload – Auto Resize Compress-Reduce 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!.

Recommended For You.

PHP Image Compression before Uploading Today, We want to share with you PHP Image Compression before Uploading. In this post we will

Add a Comment

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