title: Upload 2 files php
body: <p>I have a problem with transferring files.
  What am I doing wrong why can not I upload two files?
  I can send one ($_FILES['filename'] when I add this ($_FILES['filename']['filename2'] did not work. Maybe there's another way to send 2 files?</p>
  
  <p>php </p>
  
  <pre><code>&lt;?php # Script - upload_image.php
  
  // Check if the form has been submitted:
  if (isset($_POST['submitted'])) {
  
      // Check for an uploaded file:
      if (isset($_FILES['filename']['filename2'])) {
  
          // Validate the type. Should be JPEG or PNG.
          $allowed = array ('image/pjpeg', 'image/jpeg', 'image/JPG', 'image/X-PNG', 'image/PNG', 'image/png', 'image/x-png');
          if (in_array($_FILES['filename']['filename2']['type'], $allowed)) {
  
              // Move the file over.
              if (move_uploaded_file ($_FILES['filename']['filename2']['tmp_name'], "../images/{$_FILES['filename']['filename2']['name']}")) {
                  echo '&lt;p&gt;&lt;em&gt;The file has been uploaded!&lt;/em&gt;&lt;/p&gt;';
              } // End of move... IF.
  
          } else { // Invalid type.
              echo '&lt;p class="error"&gt;Please upload a JPEG or PNG image.&lt;/p&gt;';
          }
  
      } // End of isset($_FILES['upload']) IF.
  
      // Check for an error:
  
      if ($_FILES['filename']['filename2']['error'] &gt; 0) {
          echo '&lt;p class="error"&gt;The file could not be uploaded because: &lt;strong&gt;';
  
          // Print a message based upon the error.
          switch ($_FILES['filename']['filename2']['error']) {
              case 1:
                  print 'The file exceeds the upload_max_filesize setting in php.ini.';
                  break;
              case 2:
                  print 'The file exceeds the MAX_FILE_SIZE setting in the HTML form.';
                  break;
              case 3:
                  print 'The file was only partially uploaded.';
                  break;
              case 4:
                  print 'No file was uploaded.';
                  break;
              case 6:
                  print 'No temporary folder was available.';
                  break;
              case 7:
                  print 'Unable to write to the disk.';
                  break;
              case 8:
                  print 'File upload stopped.';
                  break;
              default:
                  print 'A system error occurred.';
                  break;
          } // End of switch.
  
          print '&lt;/strong&gt;&lt;/p&gt;';
  
      } // End of error IF.
  
      // Delete the file if it still exists:
      if (file_exists ($_FILES['filename']['filename2']['tmp_name']) &amp;&amp; is_file($_FILES['filename']['filename2']['tmp_name']) ) {
          unlink ($_FILES['filename']['filename2']['tmp_name']);
      }
  
  } // End of the submitted conditional.
  ?&gt;
  </code></pre>
  
  <p>form</p>
  
  <pre><code>&lt;form enctype="multipart/form-data" action="photo_upload_6.php" method="post"&gt;
  
      &lt;input type="hidden" name="MAX_FILE_SIZE" value="524288"&gt;
  
      &lt;fieldset&gt;&lt;legend&gt;Select a JPEG or PNG image of 512KB or smaller to be uploaded:&lt;/legend&gt;
  
         &lt;li&gt;
          &lt;label for="filename"&gt;Image:&lt;/label&gt;
          &lt;input name="filename" type="file" id="filename" tabindex="10"&gt;
         &lt;/li&gt;
  
         &lt;li&gt;
          &lt;label for="filename2"&gt;Image2:&lt;/label&gt;
          &lt;input name="filename2" type="file" id="filename2" tabindex="15"&gt;
         &lt;/li&gt;
  
      &lt;/fieldset&gt;
      &lt;div align="center"&gt;&lt;input type="submit" name="submit" value="Submit" /&gt;&lt;/div&gt;
      &lt;input type="hidden" name="submitted" value="TRUE" /&gt;
  &lt;/form&gt;
  </code></pre>