Jump to content

Uploading Images


shasta

Recommended Posts

Ok, so I have a script with a Browse bar to search the client computer and they can choose a picture to upload. It will upload the picture, resize it, and save the resized image in a certain directory (named goodsimages).

 

Other things I need it to do:

-I need it to post that resized image to another page, so when multiple images are uploaded it will post them all in a row, or table-like format where other users can view them.

 

-On the page with the Browse/upload function I also need an area to type in a URL that will be added as a link to the final thumbnail on the other page.

 

-Need an input box to type a short description of the item in the picture (i.e. Wrench, bike, etc.)

 

Here is the script I have right now (named upload.php):

<?php

 

// This is the temporary file created by PHP

$uploadedfile = $_FILES['uploadfile']['tmp_name'];

 

// Create an Image from it so we can do the resize

$src = imagecreatefromjpeg($uploadedfile);

 

// Capture the original size of the uploaded image

list($width,$height)=getimagesize($uploadedfile);

 

// For our purposes, I have resized the image to be

// 600 pixels wide, and maintain the original aspect

// ratio. This prevents the image from being "stretched"

// or "squashed". If you prefer some max width other than

// 600, simply change the $newwidth variable

$newwidth=150;

$newheight=($height/$width)*$newwidth;

$tmp=imagecreatetruecolor($newwidth,$newheight);

 

// this line actually does the image resizing, copying from the original

// image into the $tmp image

imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);

 

// now write the resized image to disk. I have assumed that you want the

// resized, uploaded image file to reside in the ./images subdirectory.

$filename = "goodsimages/". $_FILES['uploadfile']['name'];

imagejpeg($tmp,$filename,100);

 

imagedestroy($src);

imagedestroy($tmp); // NOTE: PHP will clean up the temp file it created when the request

// has completed.

?>

 

And here is the html part I have for it:

<form action="upload.php" method="post" enctype="multipart/form-data" >

<input type="file" name="uploadfile"/>

<input type="submit"/>

</form>

Link to comment
https://forums.phpfreaks.com/topic/148612-uploading-images/
Share on other sites

Archived

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

×
×
  • 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.