Image Uploading And Resizing

They have: 10 posts

Joined: Feb 2004

im needing a script that uploads an image to a certain directory than say copies a thunmbnail version of the image in the thumbs directory.

<?php


$uploaddir
= \"/home/swimtige/public_html/img/pics/\"; // Path to full image folder

if (move_uploaded_file(
$_FILES[\"userfile\"][\"tmp_name\"], $uploaddir . $_FILES[\"userfile\"][\"name\"]))

{

// Move the original uploaded file to the pics directory

$picture = $uploaddir . $_FILES[\"userfile\"][\"name\"]; // /home/swimtige/public_html/img/pics/pic.jpg
$picture_name = $_FILES[\"userfile\"][\"name\"]; // pic.jpg
// Set a few variables


$size = getimagesize(\"$picture\");
$width = $size[0];
$height = $size[1]; // Find out the height and width attriutes of image
$newHeight = 100;
$newWidth = 100; // Set the new height and width of thumbnail


$oldimage = ImageCreateFromJPEG(\"$picture\");
$newimage = ImageCreateTrueColor($newWidth,$newHeight);
imagecopyresampled(
$newimage,$oldimage,0,0,0,0,$newWidth,$newHeight,$width,$height);

ImageJPEG(
$newimage,\"$picture_name\");
// Thumbnail picture is created in /upload/ dir

copy(
$picture_name, \"/home/swimtige/public_html/img/thumbs/$picture_name\");
// So move it to /thumbnail/ dir

unlink(\"home/swimtige/public_html/upload/
$picture_name\");
// Delete the useless thumbnail in /upload/ dir

}

else {
echo \"Image upload failed!\";
}
?>

i used the above php script but this returns the error message
"Fatal error: imagecreatetruecolor(): requires GD 2.0 or later in /home/......./ting.php on line 15" how do i solve this problem.

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

Install GD? Or if it's installed, change the pointer so the script knows where it is?

He has: 1,380 posts

Joined: Feb 2002

ok number one, it looks like the script I gave you, so there's a few things

#1- your path is set as ones that it looks like i forgot to take out
change /home/swimtige/public_html to whatever the path is to your site, all 3 times it occurs
#2- make sure your folders are setup as they are in the script, or edit the script to match your folder system

They have: 10 posts

Joined: Feb 2004

all the paths on the proper script are set correctly, i guess i cant install GD myself so ive asked my host what version of GD they have its V1.6.2 does this sound right??

anway...is there a script that will do the job that i can run using GD 1.6.2

He has: 1,380 posts

Joined: Feb 2002

the paths are obviously NOT set correctly because home/swimtige/public_html is what my server is, and unless you have the same domain name, with the same account name, I guaruntee that is wrong

They have: 10 posts

Joined: Feb 2004

sorry for misleading you i meant the paths are deffinatly correct, on the proper script i am running on my server, the script i posted above was the orignal taken from one of your earlier posts i believe

He has: 1,380 posts

Joined: Feb 2002

then post the correct one

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.