neogemima Posted May 12, 2009 Share Posted May 12, 2009 So I have a form that allows users to upload 3 files. In my php page I have a conditional statement to test the files. It's pretty large. I want to make it so that it tests if the image is of a certain file type, certain size, or if it's not there (if the user has no file to upload). The thing it doesn't do is allow the user to leave a file upload field blank if they do not have an image. What should I add to this conditional statement to allow that? <?php if ((($_FILES['img1']['type'] == "image/gif") || ($_FILES['img1']['type'] == "image/jpeg") || ($_FILES['img1']['type'] == "image/pjpeg")) && (($_FILES['img2']['type'] == "image/gif") || ($_FILES['img2']['type'] == "image/jpeg") || ($_FILES['img2']['type'] == "image/pjpeg")) && (($_FILES['img3']['type'] == "image/gif") || ($_FILES['img3']['type'] == "image/jpeg") || ($_FILES['img3']['type'] == "image/pjpeg")) && ($_FILES['img1']['size'] <= 150000) && ($_FILES['img2']['size'] <= 150000) && ($_FILES['img3']['size'] <= 150000)) { //code continues ?> That and any way to trim this statement down a bit would be great. Thanks ahead. Link to comment https://forums.phpfreaks.com/topic/157891-file-upload-conditional-statement-help/ Share on other sites More sharing options...
Ken2k7 Posted May 12, 2009 Share Posted May 12, 2009 You can check the name of the file. Link to comment https://forums.phpfreaks.com/topic/157891-file-upload-conditional-statement-help/#findComment-832837 Share on other sites More sharing options...
neogemima Posted May 12, 2009 Author Share Posted May 12, 2009 Right, but how would I include that in the if statement, or do I have to make individual if statements after this? Link to comment https://forums.phpfreaks.com/topic/157891-file-upload-conditional-statement-help/#findComment-832843 Share on other sites More sharing options...
gevans Posted May 12, 2009 Share Posted May 12, 2009 Realistically running seperate if statments will help you out with both your debbugging, and setting errors which I imagine you want to do. I'd recommend looking at http://uk3.php.net/manual/en/features.file-upload.post-method.php Link to comment https://forums.phpfreaks.com/topic/157891-file-upload-conditional-statement-help/#findComment-832846 Share on other sites More sharing options...
PFMaBiSmAd Posted May 12, 2009 Share Posted May 12, 2009 Use an array, then use a loop - http://www.phpfreaks.com/forums/index.php/topic,251778.msg1182671.html#msg1182671 You never repeat code when you have multiple same-type data, that is bad programming, unless you like typing (and debugging the typing errors) and changing each occurrence of the code every time you make a minor change such as which file types to allow. Link to comment https://forums.phpfreaks.com/topic/157891-file-upload-conditional-statement-help/#findComment-832866 Share on other sites More sharing options...
Ken2k7 Posted May 13, 2009 Share Posted May 13, 2009 PFMaBiSmAd is not saying that the unless case is considered good programming. Well I guess in a way he could have meant that. Not sure... Link to comment https://forums.phpfreaks.com/topic/157891-file-upload-conditional-statement-help/#findComment-832867 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.