HomeSunday, June 24, 2018, 01:45:22
-1

Upload and Resize an Image with PHP

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

Bookmark Script

Allow your users to easily bookmark your site, by clicking on a link on the page.

MySQL Basic Functions

MySQL Basic Functions - select, delete, update..

PHP File Create

Create and write data to a file using the php frwite function.

ShoutBox 1.1. PHP Script

ShoutBox allows your users to post short messages on your site. The script is lightweight and very easy to install and use.

PHP/MySQL Bookmarklet - PHP Tutorial

PHP/MySQL bookmarklet, bookmark current page, PHP/MySQL tutorial.

Contact Us 2.0. :: PHP Form

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

Smarty - Create dynamic Web Pages with PHP & MySQL

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

PHP Date Examples

Returns a string formatted according to the given format string using the given integer timestamp or the current time if no timestamp is given.

PHP Fwrite : fwrite

php write to file - how to write data to a file using the php frwite function

Send This Link PHP Script

A popup form which allows your visitors to send a referral link from your site. It features admin notification and HTML output.
About Author

wain

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