upload images

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I am not an experienced PHP programmer and have look on the net for
what I want to do.

I'd like to allow the user on my website to upload two images one is to
be turned into a thumbnail and one is to be turned into something of
around 500 x 300, one stored in a thumbnail folder and one stored in an
image folder.

I can do it individually from different pages but not from the same

Could someone point me in the direction of a script that does something
like what I am after.

Many thanks

Re: upload images

Hi Darren,

why do you need two forms??

you just need one form with one <INPUT TYPE='file' NAME='upfile'...
(the user selects his image with this input field)
then post the form....
after it you get your file with $_FILES[ upfile ]...

then process $_FILES[ upfile ][ tmp_name ]:

for your main graphic create a new image with: $bigImage =
imagecreate($newWidth, $newHeight);
in your case $newWidth must be 500; $newHeight = 300

$origImage = imagecreatefrom*( $_FILES[ upfile ][ tmp_name] );
Notice: * depends on filetype: e.g. jpg, gif, png --> have a look on
php.net: imagecreatefromjpeg

to get the original height and width you need the getimagesize command:
$infos = getimagesize($_FILES[ upfile ][ tmp_name ]);
$origWidth = $infos[0];
$origHeight = $infos[1];

imagecopyresampled($bigImage, $origImage, 0, 0, 0, 0, $newWidth,
$newHeight, $origWidth, $origHeight);
Notice: * depends on filetype: e.g. jpg, gif, png --> have a look on
php.net: e.g. imagegif

just do the same for your thumbs (you just want a smaller
imagecopyresampled($thumbImage, $origImage, 0, 0, 0, 0, $newWidth,
$newHeight, $origWidth, $origHeight);


Re: upload images

Thanks Flo,

Re: upload images

Quoted text here. Click to load it

check out this php class:

you'll need to register to download it, but it's a great toolset for working  
with images (resizing, copying, etc.)

- kevin  

Site Timeline