Greetings!
I am succesfully uploading an image via a web-form, but i would like to take that image, resize it, and place the new image in a different folder.
I am using the following code, and I have finallymanaged to not get any errors. But when I check, I do not see the new image in the second folder. (Yes, both folders have appropriate permissions.)
The first (uploaded) image is placed in ../pics. I want the altered image to be placed in ../picsth
Below is the code I am using. The image manipulation commands are all supported.
Thanks in advance for any help!
// function that resizes the image
function resizeImage($filename, $max_width, $max_height)
{
list($orig_width, $orig_height) = getimagesize($filename);
$width = $orig_width;
$height = $orig_height;
taller
if ($height > $max_height) {
$width = ($max_height / $height) * $width;
$height = $max_height;
}
wider
if ($width > $max_width) {
$height = ($max_width / $width) * $height;
$width = $max_width;
}
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0,
$width, $height, $orig_width, $orig_height);
return $image_p;
}
//If a file is submited with the form
if ($file_name) {
$path_to_file = "../pics/";
$location = $path_to_file.$file_name;
copy($file,$location);
//retrieve the newly uploaded image for resizing
$newfile="../pics/".$file_name;
resizeImage($newfile, 150, 150);
$newpath_to_file = "../picsth/";
$location = $newpath_to_file.$file_name;
// $image_p is supposedly the function return.
copy($image_p,$location);
}
////////////////////////////////////////////////////
I've tried mixing and matching just about everything. I even (somehow) got it to place the resized image in the original folder which resulted in two identical file names!
Help!