Page 1 of 1

resize uploaded image and save to location on server.

Posted: Sun May 17, 2009 7:28 pm
by kayo_potato
Hello,

I am trying to upload an image received from a form and then save it as is and also at a smaller size.

Can anyone tell me why this is not working?

Code: Select all

This is the part of the code that processes the form:
//upload the image received in the form. this works fine, using ftp
upload($_FILES['uploadedfile']['tmp_name'], 'Images/test/large/', $_FILES['uploadedfile']['name']); 
//point to uploaded file
$target_path="Images/test/".$_FILES['uploadedfile']['name'];
//make new image of correct dimensions for thumbnail
$projthumb=imagecreatetruecolor($thumbwidth, $thumbheight);
//resize the source image into the destination image
$source = imagecreatefromjpeg($target_path);
imagecopyresampled($projthumb, $source, 0,0,0,0, $thumbwidth, $thumbheight, 762, 372);
//make save jpeg to thumbnail location
imagejpeg($projthumb, 'Images/Thumbs/newimage.jpeg', 85);
imagedestroy($projthumb);
This is driving me mad, I just don't know what to do, if anyone could help me I would be extremely grateful.
Thanks

Re: resize uploaded image and save to location on server.

Posted: Sun May 17, 2009 7:49 pm
by Gabriel
Please use the correct tags for displaying PHP code: [ code=php ]...[/ code ]

Are you receiving any kind of error when you execute the code? You can find a tutorial explaining image resizing with PHP. The tutorial explains resizing images without messing up the image's proportion.

Re: resize uploaded image and save to location on server.

Posted: Sun May 17, 2009 8:12 pm
by kayo_potato
Thanks,
I have read that tutorial, but to no avail.
I am not receiving any error messages.

Re: resize uploaded image and save to location on server.

Posted: Mon May 18, 2009 8:21 am
by temidayo
if the user-defined upload function works fine, then I suspect something
is wrong with your path.

Take a look at line 9: your target_path.

You are creating your source from a file that is not yet existing.

Re: resize uploaded image and save to location on server.

Posted: Mon May 18, 2009 8:33 am
by kayo_potato
Thanks guys for your help - my code wasn't the problem, it was actually my permissions on the server.
Thanks again,
kayo