Jump to content

Excluding $_FILES error number 4


rick.emmet

Recommended Posts

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

Link to comment
Share on other sites

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)){
  //..
}

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.