Greetings coders. Here is my problem. I know it lies within the ImageCreateFromJPEG function below. This script loops through a certain amount of uploads, creates a white 300x300 images, copies and resizes(scales) the uploaded image into the new 300x300 image, saves it, moves it, and deletes the temporary files. I have included the code below. I am getting these errors.
Warning: getimagesize: Unable to open 'Resource id #2' for reading. in... on line 261
Warning: imagecopyresampled(): supplied argument is not a valid Image resource... on line 287
$files = $_FILES['pfiles'];
for ($u=0; $u<$PostedUploads; $u++) {
if (is_uploaded_file($files['tmp_name'][$u])) {
//Save file to temporary location
move_uploaded_file($files['tmp_name'][$u],"images/tmp-" . substr(strtoupper($files['name'][$u]),0,-4) . ".jpg");
$ogfile=ImageCreateFromJPEG("images/tmp-" . substr(strtoupper($files['name'][$u]),0,-4) . ".jpg");
$newfilename="images/" . substr(strtoupper($files['name'][$u]),0,-4) . ".jpg";
//Create new file that is 300x300 with white background
$newimage=ImageCreateTrueColor(300,300);
$white = ImageColorAllocate($newimage, 255, 255, 255);
ImageFill($newimage,0,0,$white);
//Grab Orginals Dimensions
$size=GetImageSize($ogfile);
$ix=$size[0];
$iy=$size[1];
//Set Scale
if($ix>$iy) {
$scale=300/$ix;
} else {
$scale=300/$iy;
};
//Set cordinates on the new image
$newx=round(((300-($scale*$ix))/2),0);
$newy=round(((300-($scale*$iy))/2),0);
$neww=round(($scale*$ix),0);
$newh=round(($scale*$iy),0);
//Display Info for debugging.
$ErrMSG.="Name=" . $newfilename;
$ErrMSG.="<br>Width=" . $ix;
$ErrMSG.="<br>Height=" . $iy;
$ErrMSG.="<br>Scale=" . $scale;
$ErrMSG.="<br>New X=" . $newx;
$ErrMSG.="<br>New Y=" . $newy;
$ErrMSG.="<br>New W=" . $neww;
$ErrMSG.="<br>New H=" . $newh;
$ErrMSG.="<br>";
//Copy the resize to new image and center it
ImageCopyResampled($newimage,$temp_im,$newx,$newy,0,0,$neww,$newh,$ix,$iy);
//Save new image in products folder delete temp image
ImageJPEG($newimage,$newfilename,100);
ImageDestroy($ogfile);
copy($newfilename,"../ftimages/products/" . substr(strtoupper($files['name'][$u]),0,-4) . ".jpg");
unlink($newfilename);
$ErrMSG.=$newfilename . " - Successful<br>";
} else {
$ErrMSG.=strtoupper($files['name'][$u]) . " - Failed<br>";
};
};
Any Help or suggestions would be wonderful. Thanks!