Im trying to get an image upload script to work within a session file.....i can get it to work on a single page without any other script....but i need to have the image upload facility built into a add product form....so the script is currently sitting in a session file at the same point as where the fields are all validatedd....i 've tried using copy and move_uploaded_f ile.
I know the structure of the code is probably not great but i cant seem to find out why it wont work.
$subimgfile is the variable name for $_FILES['imgfile']['name']
and $subimgfiletype is the variable name for $_FILES['imgfile']['type']
I know the structure of the code is probably not great but i cant seem to find out why it wont work.
$subimgfile is the variable name for $_FILES['imgfile']['name']
and $subimgfiletype is the variable name for $_FILES['imgfile']['type']
Code:
if ($subimgfile) { $uploaddir = "./product_images"; if (($subimgfiletype != "image/gif") && ($subimgfiletype != "image/jpeg") && ($subimgfiletype != "image/pjpeg")) { $form->setError($field, "* Image Must be .jpg / .jpeg or .gif, your file had extension $subimgfiletype"); unlink($subimgfile); } $imgsize = GetImageSize($subimgfile); if (($imgsize[0] > 531) || ($imgsize[1] > 398)) { $tmpimg = tempnam("/tmp", "MKUP"); system("djpeg $subimgfile >$tmpimg"); system("pnmscale -xy 531 398 $tmpimg | cjpeg -smoo 10 -qual 80 >$subimgfile"); unlink($tmpimg); } $final_filename = str_replace(" ", "_", $subimgfile); $FileCounter = 1; while (file_exists( 'product_images/'.$final_filename )) $final_filename = $FileCounter++.$final_filename; $newfile = $uploaddir . "/$final_filename"; if (!copy($subimgfile,"$newfile")) { $form->setError($field, "* Error uploading file"); } unlink($subimgfile); }
Comment