如何上传文件夹中包含文件夹和文件的文件夹的所有内容?

How can I upload the contents of a folder including a files and folders inside of a folder?

I already try this function, but the problem is the FILES only is uploading, the folder inside of a folder is not uploading.

//html
<form method="post" id="user_form" enctype="multipart/form-data">
<div class="modal-content">
<div class="modal-header">
 <button type="button" class="close" data-dismiss="modal">&times;</button>
 <h4 class="modal-title">Add User</h4>
</div>
<div class="modal-body">
 <label>Enter Folder Name</label>
 <input type="text" name="text_firstname" id="text_firstname" class="form-control" />
 <br />
 <label>Select Folder</label>
 <input type="file" name="user_image[]" id="files" multiple directory="" webkitdirectory="" mozdirectory="" onchange="selectFolder(event)" />
 <span id="user_uploaded_image"></span>
</div>
<div class="modal-footer">
 <input type="hidden" name="user_id" id="user_id" />
 <input type="hidden" name="operation" id="operation" />
 <input type="submit" name="action" id="action" class="btn btn-success" value="Add" />
 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</form>

//script
<script type="text/javascript">
$(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]);
}

</script>

//insert.php ~ PHP CODE
<?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 => $name) {
            if (strlen($_FILES['user_image']['name'][$i]) > 1) {
                move_uploaded_file($_FILES['user_image']['tmp_name'][$i], $folder_name.'/'.$name);
            }
        }

        echo "FOLDER UPLOADED";
    }
    else
    {
        echo "ERROR";
    }

 ?>

I expect that the all files and folders the I uploaded is must be uploaded including FOLDERS AND FILES. Please help me out of this problem. Thank you in advance!

duanping2809
duanping2809 不同的交易当它成为文件夹上传时,请帮我解决这个问题。谢谢!@SvenMich
11 个月之前 回复
dpwdldgn43486
dpwdldgn43486 通过HTML表单上传整个目录的可能重复
11 个月之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐