Fallen_angel Posted November 30, 2006 Share Posted November 30, 2006 Hi , I have an upload script that uploads images to my file server , resizes them and then inserts the value's into a database for referancing later on , I am hoping somone can help me with an if statement that I just don't seem to be getting right , basicly to give you a bit of background my information is passed by a form , using an aray for the uploads , the arrays I need to work with are $return[$i]['name'] $return[$i]['size'] & $return[$i]['type'] which are refered to individually by calling a digit inside the [] ( for exampel for the name of the seccond uplaod it would be ) $return[2]['name ']now the script itself works pretty fine if the user uploads two images they get no errors , however if they only upload one image , or if they upload an invalid file type it will spit out a series of errors on teh processing page which is obiously tellign me it couldn't do it because image 2 wasn't uploaded and therefore doesn't exist to work with, the actual uploading part of my script I have already managed to make it so it won't try to execute if there isn't a seccond file , however because I do my resizing as two seperate functions ( one for each ) one is always goign to fail untill I work out an if statement or unless I can work out how to do the rezising usign the aray instead of using the filenames themselfs anyways enough blabbering here is the resize seciton of my script , I really hope somone can assist [code]$img1_name=$return[1]['name'];$img1_type=$return[1]['type'];$img2_name=$return[2]['name'];$img2_type=$return[2]['type'];$strain_id=$_POST['strain_id'] ;$submitter=$_POST['submitter'];$comments=$_POST['comments'];/* resize script1 */$im_file_name = './uploads/'.$img1_name.$img1_type; $image_attribs = getimagesize($im_file_name); $im_old = imageCreateFromJpeg($im_file_name); $th_max_width = 144; $th_max_height = 144; $ratio = ($width > $height) ? $th_max_width/$image_attribs[0] : $th_max_height/$image_attribs[1]; $th_width = $image_attribs[0] * $ratio; $th_height = $image_attribs[1] * $ratio; $im_new = imagecreatetruecolor($th_width,$th_height); imageAntiAlias($im_new,true); $th_file_name = './uploads/thumbs/' . $img1_name.$img1_type; imageCopyResampled($im_new,$im_old,0,0,0,0,$th_width,$th_height, $image_attribs[0], $image_attribs[1]); imageJpeg($im_new,$th_file_name,100); /* resize script part2 */$im_file_name2 = './uploads/'.$img2_name.$img2_type; $image_attribs2 = getimagesize($im_file_name2); $im_old2 = imageCreateFromJpeg($im_file_name2); $ratio = ($width > $height) ? $th_max_width/$image_attribs2[0] : $th_max_height/$image_attribs2[1]; $th_width2 = $image_attribs2[0] * $ratio; $th_height2 = $image_attribs2[1] * $ratio; $im_new2 = imagecreatetruecolor($th_width2,$th_height2); imageAntiAlias($im_new2,true); $th_file_name2 = './uploads/thumbs/' . $img2_name.$img2_type; imageCopyResampled($im_new2,$im_old2,0,0,0,0,$th_width2,$th_height2, $image_attribs2[0], $image_attribs2[1]); imageJpeg($im_new2,$th_file_name2,100); [/code]so in short basicly what i need to do is now have the part under resize script part 2 run UNLESS there is a seccond file uploaded thanx in advance Quote Link to comment https://forums.phpfreaks.com/topic/28958-help-with-an-if-statement-least-i-think-thats-the-best-option-lol/ Share on other sites More sharing options...
btherl Posted November 30, 2006 Share Posted November 30, 2006 Can you just use [code=php:0] if (isset($return[2])) { resize part 2 }[/code]? And the same for checking for image 1. Quote Link to comment https://forums.phpfreaks.com/topic/28958-help-with-an-if-statement-least-i-think-thats-the-best-option-lol/#findComment-132625 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.