Jump to content

Archived

This topic is now archived and is closed to further replies.

bigshwa05

PHP Jpeg Thumbnail Creation

Recommended Posts

Hi there,

This is the first time i ve worked with the GD library. I am very new to php so heres what i am trying to do.

I have created a simple HTML Form that looks like so.

#############################

<form action="php.php" method="$_POST" enctype="multipart/form-data">
Upload Image: <input type="file" name="imagename">
<font size="1">Click browse to upload a local file</font>
<input type="submit" value="Upload Image">
</form>

#############################

Now i am trying to use this PHP script named php.php to accept the image from that form and process it accordingly

<?php
// Get File and set new size
$filename = $_GET["$imagename"];
$percent = 0.5;

// Content type
header('Content-type: image/jpeg');

// Get new sizes
list($width, $height) = getimagesize($filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;

// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);

// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

// Output
imagejpeg($thumb);
?>

###################

The form seems to be passing the files name over to the form but it is not actually passing the image which is what i would like.

Any advice would be greatly appreciated.

Bigshwa

Share this post


Link to post
Share on other sites
Change this:
<form action="php.php" method="$_POST" enctype="multipart/form-data">
To this:
<form action="php.php" method="post" enctype="multipart/form-data">

Change this:
$filename = $_GET["$imagename"];
To this:
$filename = $_FILES['imagename']['tmp_name'];

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.