1

Currently, I'm developing an application for uploading folders and files. I have two problems: I can't upload files by keeping the tree (subfolders and their files).Here is the code:

<form method="post" action='post_upload.php' enctype="multipart/form-data">
<input type="file" name="files[]" id="files" webkitdirectory directory multiple>
<input class="button" type="submit" value="Upload" />

post_upload.php:

if ($_SERVER['REQUEST_METHOD'] == 'POST'){
foreach ($_FILES['files']['name'] as $i => $name) {
    if (strlen($_FILES['files']['name'][$i]) > 1) {
        if (move_uploaded_file($_FILES['files']['tmp_name'][$i], 'upload/'.$name)) {
            echo $name."<br>";
        }
    }
}

If this problem is resolved, then it is possible to select more than one folder?

Thanks.

khaled
  • 77
  • 1
  • 8

1 Answers1

2

There is alternative way to do it using javascript. In javascript you will get webkitRelativePath. check example here

Ahmed Ginani
  • 6,522
  • 2
  • 15
  • 33