resize uploaded image and save to location on server.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kayo_potato
Forum Newbie
Posts: 7
Joined: Sat May 16, 2009 11:55 am

resize uploaded image and save to location on server.

Post 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
Last edited by Benjamin on Mon May 18, 2009 10:12 am, edited 1 time in total.
Reason: Changed code type from text to php.
User avatar
Gabriel
Forum Commoner
Posts: 41
Joined: Wed May 06, 2009 8:12 pm
Location: Las Vegas

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

Post 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.
kayo_potato
Forum Newbie
Posts: 7
Joined: Sat May 16, 2009 11:55 am

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

Post by kayo_potato »

Thanks,
I have read that tutorial, but to no avail.
I am not receiving any error messages.
temidayo
Forum Contributor
Posts: 109
Joined: Fri May 23, 2008 6:17 am
Location: Nigeria

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

Post 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.
kayo_potato
Forum Newbie
Posts: 7
Joined: Sat May 16, 2009 11:55 am

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

Post 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
Post Reply