title: How can I upload all contenst of a folder including folders and files inside of a folder?
body: <p>How can I upload the contents of a folder including a files and folders inside of a folder?</p>
  
  <p>I already try this function, but the problem is the <em>FILES</em> only is uploading, the folder inside of a folder is not uploading.</p>
  
  <pre><code>//html
  &lt;form method="post" id="user_form" enctype="multipart/form-data"&gt;
  &lt;div class="modal-content"&gt;
  &lt;div class="modal-header"&gt;
   &lt;button type="button" class="close" data-dismiss="modal"&gt;&amp;times;&lt;/button&gt;
   &lt;h4 class="modal-title"&gt;Add User&lt;/h4&gt;
  &lt;/div&gt;
  &lt;div class="modal-body"&gt;
   &lt;label&gt;Enter Folder Name&lt;/label&gt;
   &lt;input type="text" name="text_firstname" id="text_firstname" class="form-control" /&gt;
   &lt;br /&gt;
   &lt;label&gt;Select Folder&lt;/label&gt;
   &lt;input type="file" name="user_image[]" id="files" multiple directory="" webkitdirectory="" mozdirectory="" onchange="selectFolder(event)" /&gt;
   &lt;span id="user_uploaded_image"&gt;&lt;/span&gt;
  &lt;/div&gt;
  &lt;div class="modal-footer"&gt;
   &lt;input type="hidden" name="user_id" id="user_id" /&gt;
   &lt;input type="hidden" name="operation" id="operation" /&gt;
   &lt;input type="submit" name="action" id="action" class="btn btn-success" value="Add" /&gt;
   &lt;button type="button" class="btn btn-default" data-dismiss="modal"&gt;Close&lt;/button&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/form&gt;
  
  //script
  &lt;script type="text/javascript"&gt;
  $(document).ready(function(){
  
   $(document).on('submit', '#user_form', function(event){
    event.preventDefault();
    var firstName = $('#text_firstname').val();
    if(firstName != '')
    {
     $.ajax({
      url:"insert.php",
      method:'POST',
      data:new FormData(this),
      contentType:false,
      processData:false,
      beforeSend:function(data)
      {
          $(".preload").show();
      },
      success:function(data)
      {
       // alert(data);
       $('#user_form')[0].reset();
       $(".preload").hide();
      }
     });
    }
    else
    {
     alert("Both Fields are Required");
    }
   });
  
  
  
  });
  
  function selectFolder(e) {
      var theFiles = e.target.files;
      var relativePath = theFiles[0].webkitRelativePath;
      var folder = relativePath.split("/");
      $("#text_firstname").val(folder[0]);
  }
  
  &lt;/script&gt;
  
  //insert.php ~ PHP CODE
  &lt;?php 
  
      if ($_POST['text_firstname'] != "") {
          $folder_name = "uploads" .'/'. $_POST['text_firstname'];
          if (!is_dir($folder_name))
              mkdir($folder_name);
          foreach ($_FILES['user_image']['name'] as $i =&gt; $name) {
              if (strlen($_FILES['user_image']['name'][$i]) &gt; 1) {
                  move_uploaded_file($_FILES['user_image']['tmp_name'][$i], $folder_name.'/'.$name);
              }
          }
  
          echo "FOLDER UPLOADED";
      }
      else
      {
          echo "ERROR";
      }
  
   ?&gt;
  </code></pre>
  
  <p>I expect that the all files and folders the I uploaded is must be uploaded including <em>FOLDERS AND FILES</em>. Please help me out of this problem. Thank you in advance!</p>