title: Make directory and upload multiple file into created directory PHP
body: <p>I have been digging for an answer for many days. how do i upload multiple file to the newly created directory. If you look into <strong>file_upload.php</strong> you will find two <code>$upload_dir</code> variable. So, let's call first <code>$upload_dir</code> as direct folder and Second, <code>$upload_dir</code> as make dir. Simple</p>
  <p>So, When I select first <code>$upload_dir</code> it does upload all files directly into the folder and When I select second <code>$upload_dir</code> what it does is create a random folder but unable to upload any file.</p>
  <p>I want to upload multiple file into newly created folder</p>
  <p>I did refer this <a href="https://stackoverflow.com/questions/25555422/php-upload-multiple-photos-into-newly-created-directory">PHP - Upload multiple photos into newly created Directory</a> and <a href="https://stackoverflow.com/questions/26203353/multiple-file-upload-and-store-them-in-a-directory">Multiple file upload and store them in a directory</a> but didn't work for me</p>
  <p><strong>index.php</strong></p>
  <pre><code>&lt;form action=&quot;file_upload.php&quot; method=&quot;POST&quot;
              enctype=&quot;multipart/form-data&quot;&gt; 
    
          &lt;h2&gt;Upload Files&lt;/h2&gt; 
            
          &lt;p&gt; 
              Select files to upload:  
                
              &lt;!-- name of the input fields are going to 
                  be used in our php script--&gt;
              &lt;input type=&quot;file&quot; name=&quot;files[]&quot; multiple&gt; 
                
              &lt;br&gt;&lt;br&gt; 
                
              &lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Upload&quot; &gt; 
          &lt;/p&gt; 
      &lt;/form&gt;  
  </code></pre>
  <p><strong>file_upload.php</strong></p>
  <pre><code>&lt;?php  
    
  // session_start();
  // Check if form was submited 
  if(isset($_POST['submit'])) { 
    
      // Configure upload directory and allowed file types 
      $rand_name = rand(1, 10000);
      // $upload_dir = 'C:/fileUpload/'.DIRECTORY_SEPARATOR;
      // $permit = 0777;
      $allowed_types = array('jpg', 'png', 'jpeg', 'gif'); 
      $upload_dir = mkdir('C:/fileUpload/'. $rand_name .'/'.DIRECTORY_SEPARATOR, 0777);
        
      // Define maxsize for files i.e 10MB 
      $maxsize = 10 * 1024 * 1024;  
    
      // Checks if user sent an empty form  
      if(!empty(array_filter($_FILES['files']['name']))) { 
    
          // Loop through each file in files[] array 
          foreach ($_FILES['files']['tmp_name'] as $key =&gt; $value) { 
                
              $file_tmpname = $_FILES['files']['tmp_name'][$key]; 
              $file_name = $_FILES['files']['name'][$key]; 
              $file_size = $_FILES['files']['size'][$key]; 
              $file_ext = pathinfo($file_name, PATHINFO_EXTENSION); 
    
              // Set upload file path 
              $filepath = $upload_dir.$file_name;
    
              // Check file type is allowed or not 
              if(in_array(strtolower($file_ext), $allowed_types)) { 
    
                  // Verify file size - 10MB max  
                  if ($file_size &gt; $maxsize)          
                      echo &quot;Error: File size is larger than the allowed limit.&quot;;  
    
                  // If file with name already exist then append time in 
                  // front of name of the file to avoid overwriting of file 
                  if(file_exists($filepath)) { 
                      $filepath = $upload_dir.time().$file_name; 
                        
                      if( move_uploaded_file($file_tmpname, $filepath)) { 
                          echo &quot;{$file_name} successfully uploaded &lt;br /&gt;&quot;; 
                      }  
                      else {                      
                          echo &quot;Error uploading {$file_name} &lt;br /&gt;&quot;;  
                      } 
                  } 
                  else { 
                    
                      if( move_uploaded_file($file_tmpname, $filepath)) { 
                          echo &quot;{$file_name} successfully uploaded &lt;br /&gt;&quot;; 
                      } 
                      else {                      
                          echo &quot;Error uploading {$file_name} &lt;br /&gt;&quot;;  
                      } 
                  } 
              } 
              else { 
                    
                  // If file extention not valid 
                  echo &quot;Error uploading {$file_name} &quot;;  
                  echo &quot;({$file_ext} file type is not allowed)&lt;br / &gt;&quot;; 
              }  
          } 
      }  
      else { 
            
          // If no files selected 
          echo &quot;No files selected.&quot;; 
      } 
  }  
    
  ?&gt; 
  </code></pre>
  <p>Please Help!</p>
  <p>Thank you in Advance</p>