rick.emmet Posted December 7, 2011 Share Posted December 7, 2011 Hi Everyone, I have a rather stupid question, but I haven't been able to find the correct method / syntax to do this. I want to allow users to upload a maximum of 5 photos - less then 5 is OK too. I've been testing the following script and haven't gotten it to ignore error # 4 (no file uploaded): if ($_FILES['userfile']['error'] == 1 || 2 || 3 || 6 || 7) { echo 'Problem: '; switch ($_FILES['userfile']['error']) { case 1: echo 'File exceeded upload_max_filesize'; break; case 2: echo 'File exceeded max_file_size'; break; case 3: echo 'File only partially uploaded'; break; case 6: echo 'Cannot upload file: No temp directory specified.'; break; case 7: echo 'Upload failed: Cannot write to disk.'; break; } exit; } I will be using a while loop and incrementing through the script (this is simpler version). Does anyone know the proper syntax for the IF statement ' if ($_FILES['userfile']['error'] == 1 || 2 || 3 || 6 || 7)" ? Thanks much, Rick Quote Link to comment https://forums.phpfreaks.com/topic/252686-excluding-_files-error-number-4/ Share on other sites More sharing options...
Pikachu2000 Posted December 7, 2011 Share Posted December 7, 2011 Are you allowing multiple uploads in one form, or are you trying to make sure that users have no more than 5 uploaded files active at any one time? Quote Link to comment https://forums.phpfreaks.com/topic/252686-excluding-_files-error-number-4/#findComment-1295385 Share on other sites More sharing options...
kicken Posted December 7, 2011 Share Posted December 7, 2011 Does anyone know the proper syntax for the IF statement ' if ($_FILES['userfile']['error'] == 1 || 2 || 3 || 6 || 7)" ? if (in_array($_FILES['userfile']['error'], array(1, 2, 3, 6, 7))){ However, 1) You should use the constant names for readabity 2) You'd be better off just checking for success rather than all the error types if ($_FILES['userfile']['error'] != UPLOAD_ERR_OK && $_FILES['userfile']['error'] != UPLOAD_ERR_NO_FILE)){ //.. } Quote Link to comment https://forums.phpfreaks.com/topic/252686-excluding-_files-error-number-4/#findComment-1295403 Share on other sites More sharing options...
rick.emmet Posted December 7, 2011 Author Share Posted December 7, 2011 Hello Kitchen, Thank you very much, I have never seen that before. Works like a charm! Also Pikachu2000, I am allowing up to five photos along with string data to be uploaded to the server. It's OK if they upload less then five photos. Thanks again for your help, Cheers, Rick Quote Link to comment https://forums.phpfreaks.com/topic/252686-excluding-_files-error-number-4/#findComment-1295500 Share on other sites More sharing options...
Pikachu2000 Posted December 8, 2011 Share Posted December 8, 2011 Hello Kitchen, Thank you very much, I have never seen that before. Works like a charm! Also Pikachu2000, I am allowing up to five photos along with string data to be uploaded to the server. It's OK if they upload less then five photos. Thanks again for your help, Cheers, Rick Right, but are they allowed to upload 5 in the same form submission, or are they allowed to have a grand total of 5 uploaded files on the server at any given time? Quote Link to comment https://forums.phpfreaks.com/topic/252686-excluding-_files-error-number-4/#findComment-1295616 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.