Ad block is installed and active. Please support us by disabling it.
HomeSaturday, January 20, 2018, 16:47:08
-1

Upload and Resize an Image with PHP

Monday, February 9, 15, 01:04:19, 3 Yaers Ago Via wain, Hits: 3363
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

[Example3] Tutorial - How to upload image in php.

PHP imagecreate

imagecreate() returns an image identifier representing a blank image of specified size.

PHP highlight_string - PHP Tutorial

Outputs or returns a syntax highlighted version of the given PHP code using the colors defined in the built-in syntax highlighter for PHP. Requirement(s): PHP Server.

Contact Us PHP Form 1.1.

A contact us form with email and form field validation. It allows your visitors to send you an email directly from your website.

PHP Str_replace - PHP Tutorial

This function returns a string or an array with all occurrences of search in subject replaced with the given replace value.

Syntax highlighting in Smarty

Syntax highlighting for Smarty - Google Code Prettify

PHP Jquery Form

PHP Jquery Form allow your visitors to contact you directly from your website.

PHP Mail

Sends an email.

Images In Textarea - CSS

Tutorial Images in Textarea

Preg_Match - PHP Email Validation

Validate email with preg_match in php
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.