Jump to content

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
Link to comment
https://forums.phpfreaks.com/topic/10424-php-jpeg-thumbnail-creation/
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'];
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.