javascript - Upload folder that contains subfolders and retain them?

Using a form I am trying to upload a folder that contains files and subfolders that also contains files. I got the folder to upload but when I go to my directory I see all the files in one folder including the subfolders. I want to be able to click upload and click on the folder and submit. Once that is done, if I go to my directory I find the folder with the subfolders also included inside. Here is my code
html
<form method="post" enctype="multipart/form-data" action="#">
Folder Name: <input type="text" name="foldername" /><br/>
Choose Directoryy: <input type="file" name="files[]" id="files" multiple directory="" webkitdirectory="" mozdirectory=""><br/>
<input class="button" type="submit" value="Upload" name="upload" />
</form>
php
<?php
if(isset($_POST['upload']))
{
if($_POST['foldername']!="")
{
$foldername=$_POST['foldername'];
if(!is_dir($foldername))
mkdir($foldername);
foreach($_FILES['files']['name'] as $i=>$name)
{
if(strlen($_FILES['files']['name'][$i]) > 1)
{
move_uploaded_file($_FILES['files']['tmp_name'][$i],$foldername.'/'.$name);
}
}
echo "Folder is uploaded successfully ..";
}
else
echo "Folder uploaded Failed!!";
}
?>
Answer
Solution:
The Best Approach For This Is To Upload A ZIP File And Unzip It On The Server As Mentioned In The Comments.
You Can learn more about it here: Upload Zip File and Extract the Zip
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: object of class stdclass could not be converted to string
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.