Ad block is installed and active. Please support us by disabling it.
HomeSunday, November 19, 2017, 14:12:07
-1

Upload and Resize an Image with PHP

Monday, February 9, 15, 01:04:19, 3 Yaers Ago Via wain, Hits: 2966
Tutorial - How to upload and resize image with PHP
upload.php

Code:
<?php
if(isset($_POST['Submit']))
{
$current_image=$_FILES['image']['name'];
$extension = substr(strrchr($current_image, '.'), 1);
if (($extension!= "jpg") && ($extension != "jpeg"))
{
die('Unknown extension');
}
$time = date("fYhis");
$new_image = $time . "." . $extension;
$destination="uploads/".$new_image;
$action = copy($_FILES['image']['tmp_name'], $destination);
if (!$action)
{
die('File copy failed');
}else{
echo "File copy successful";
}
//resize//
$create = imagecreatefromjpeg($destination);
$currwidth = imagesx($create);
$currheight = imagesy($create);
$ccreate = ImageCreateTrueColor(50,50);
imagecopyresampled($ccreate, $create, 0, 0, 0, 0, 50, 50,
$currwidth, $currheight);
imagejpeg($ccreate, "thumbs/".$new_image);
imagedestroy($ccreate);
imagedestroy($create);
}else{
?>
<form method="post" enctype="multipart/form-data" action="upload.php">
<input type="file" name="image" ><br>
<input type="submit" name="Submit" value="submit">
</form>
<?php
}
?>

Mister Sunday, May 22, 2011, 04:03:41

Great tutorials. Thanks for sharing, very useful for me..

Sign In

Sponsor

Related

Upload Image with PHP [Example2]

[Example2] Tutorial - How to upload and resize image with PHP

Filter Words in PHP - PHP Tutorial

Filter bad words in PHP, requirement(s): PHP server

Link Base 2.0.

Manage your links using a MySQL database. It features easy install, user submission, and an admin panel to add, edit and remove categories and links.

PHP $_SESSION

Session_start creates a session or resumes the current one based on a session identifier passed via a GET or POST request, or passed via a cookie.

Smarty - Create dynamic Web Pages with PHP & MySQL

Creating Dynamic Web Pages Using Smarty and MySQL - Requirement(s): PHP Server, MySQL

Advanced Contact Form - PHP Script

Advanced Contact Form with email and form field validation. Features: HTML Output(Response), Captcha Image.

How to check checkbox checked

Checking if checkbox is checked with jQuery

PHP Write to File

PHP Write to File :: PHP Tutorial, requirement(s): PHP server

Creating a basic bad word filter in PHP

This tutorial will show you how to create a basic bad word filter in PHP

Getimagesize

Getimagesize function will determine the size of any given image file and return the dimensions along with the file type and a height/width text string to be used inside a normal HTML IMG tag and the correspondant HTTP content type.
About Author

wain

Date Registered: Sun, Feb 8, 15
Last Time Online: Thu, Jun 15, 17
So far has created 115 entries.
wain
This author has not yet filled in any details.