doubledee Posted February 21, 2012 Share Posted February 21, 2012 Thanks to everyone's earlier help, I pretty much have my "Upload a Photo" module done. However, I am wondering if the following code snippet can be streamlined? Do I really need to check for Width and Height when above I look at if ($imageDetails = getimagesize($tempFile)){?? // ******************** // Check File-Type. * // ******************** if (empty($errors)){ if ($imageDetails = getimagesize($tempFile)){ // Image-Array Exists. $width = $imageDetails[0]; $height = $imageDetails[1]; $imageType = $imageDetails['mime']; // IS IT REDUNDANT TO CHECK THE DIMENSIONS??? // ************************ // Check for Dimensions. * // ************************ if ($width && $height){ // Width and Height Exist. // File is Image. // ************************ // Determine Image-Type. * // ************************ if ($imageType !== 'image/gif' && $imageType !== 'image/jpeg' && $imageType !== 'image/png'){ // Invalid Image-Type. $errors['upload'] = 'Image-type must be either GIF, JPG, or PNG.'; }else{ // Valid Image-Type. // Continue Processing Upload... }//End of DETERMINE IMAGE-TYPE }else{ // File Not Image. $errors['upload'] = 'Only Images can be uploaded (i.e. GIF, JPG, or PNG).'; }//End of CHECK FOR DIMENSIONS }else{ // No Image-Array. // File Not Image. $errors['upload'] = 'Only Images can be uploaded (i.e. GIF, JPG, or PNG).'; } }//End of CHECK FILE-TYPE What do you think? I am leaning towards taking the second check out for brevity... Debbie Quote Link to comment https://forums.phpfreaks.com/topic/257480-checking-for-image-redundant-code/ Share on other sites More sharing options...
kicken Posted February 21, 2012 Share Posted February 21, 2012 You only need to check the width and height if you want to enforce a maximum/minimum size. If you don't care what size the image is you do not need to check. Quote Link to comment https://forums.phpfreaks.com/topic/257480-checking-for-image-redundant-code/#findComment-1319667 Share on other sites More sharing options...
doubledee Posted February 21, 2012 Author Share Posted February 21, 2012 You only need to check the width and height if you want to enforce a maximum/minimum size. If you don't care what size the image is you do not need to check. ...because if the File is not an "Image" then this code... if ($imageDetails = getimagesize($tempFile)){ ...would return FALSE. Is that right?? Debbie Quote Link to comment https://forums.phpfreaks.com/topic/257480-checking-for-image-redundant-code/#findComment-1319668 Share on other sites More sharing options...
kicken Posted February 21, 2012 Share Posted February 21, 2012 Correct Quote Link to comment https://forums.phpfreaks.com/topic/257480-checking-for-image-redundant-code/#findComment-1319684 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.