rick.emmet Posted December 17, 2011 Share Posted December 17, 2011 Hello Everyone, I've been taking code snippets and functions from sites such as this and rewriting them for use on a project. I've been able to take these functions and iterate through a series of uploaded files to do various types of processing on them. I found a resizing function for uploaded images and have modified it only slightly – and it works great on a single file. I will allow users to upload multiple images, and I need to loop through the files and resize each one in turn. I've used While Loops for other functions and they have worked fine, but on this particular function I get a parse error, unexpected “}” (see the note in the code). I suspect that the While Loop is throwing every thing off, but I don't know of any other approach (and what I've tested so far hasn't worked). Here's the code: function resize_rename_img() { //list the width and height and maintain the photo ratio. $num = 0; while ($num < 5) { list($width, $height) = getimagesize('./uploads/'.$_FILES['userfile']['name'][$num]); //calculate the image ratio $imgratio=$width/$height; // determine the orientation of the photo if ($width > $height) { // LANDSCAPE ORIENTATION if ($width > 600) { $newWidth = 600; $newHight = $newWidth/$imgratio; //function for resize image. $resized_img = imagecreatetruecolor($newWidth,$newHight); // Identify the source photo $source = imagecreatefromjpeg('./uploads/'.$_FILES['userfile']['name'][$num]); //the resizing is going on here! imagecopyresized($resized_img, $source, 0, 0, 0, 0, $newWidth, $newHight, $width, $height); // NEED TO SAVE AND RENAME THE PHOTO ImageJpeg ($resized_img,'./uploads/'.$_FILES['userfile']['name'][$num]); // DISTROY THE TEMP IMG FILE ImageDestroy ($resized_img); } else { // Change the name of each photo rename ('./uploads/'.$_FILES['userfile']['name'][$num], './uploads/'.$_FILES['userfile']['name'][$num]); } } elseif ($height > $width) { // PORTRATE ORIENTATION if ($height > 600) { $newHight = 600; $newWidth = $newHight*$imgratio; //function for resize image. $resized_img = imagecreatetruecolor($newWidth,$newHight); // Identify the source photo $source = imagecreatefromjpeg('./uploads/'.$_FILES['userfile']['name'][$num]); //the resizing is going on here! imagecopyresized($resized_img, $source, 0, 0, 0, 0, $newWidth, $newHight, $width, $height); // NEED TO SAVE AND RENAME THE PHOTO ImageJpeg ($resized_img,'./uploads/'.$_FILES['userfile']['name'][$num]); // DISTROY THE TEMP IMG FILE ImageDestroy ($resized_img); } else { // Change the name of each photo rename ('./uploads/'.$_FILES['userfile']['name'][$num], './uploads/'.$_FILES['userfile']['name'][$num]); } } $num++ } // HERE'S WHERE THE PHP ENGINE SAYS I HAVE AN ERROR } Does anyone have a suggestion as to changing this and getting it running? Thanks much for your time! Cheers, Rick Quote Link to comment https://forums.phpfreaks.com/topic/253385-while-loop-error/ Share on other sites More sharing options...
Pikachu2000 Posted December 17, 2011 Share Posted December 17, 2011 Look at the previous line. Notice anything missing from it? Quote Link to comment https://forums.phpfreaks.com/topic/253385-while-loop-error/#findComment-1298879 Share on other sites More sharing options...
rick.emmet Posted December 17, 2011 Author Share Posted December 17, 2011 Hello Pikachu2000, Thanks for replying! I don't know what line you are referring to, is it the line before the beginning of the function? cheers, Rick Quote Link to comment https://forums.phpfreaks.com/topic/253385-while-loop-error/#findComment-1298917 Share on other sites More sharing options...
rick.emmet Posted December 18, 2011 Author Share Posted December 18, 2011 OK, I see it now! Man, sometimes I can't find simple things like that. Kind of drives me crazy! Thanks much, Rick Quote Link to comment https://forums.phpfreaks.com/topic/253385-while-loop-error/#findComment-1298918 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.