Upload a whole directory through an HTML form

后端 未结 8 1998
不思量自难忘°
不思量自难忘° 2020-11-28 12:47

Is it possible to upload a folder with a file input in the browser?

I searched and found out that this might be a browser limitation and that I might need to use a J

相关标签:
8条回答
  • 2020-11-28 13:42

    Please Try This for upload the folder :

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

    $count = 0;
    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], 'folder/'.$name)) {
                    $count++;
                }
            }
        }
    }
    

    `

    0 讨论(0)
  • 2020-11-28 13:44

    It's becoming possible with use of webkitdirectory.

    <input type="file" webkitdirectory directory multiple />
    

    Supported since Firefox 50, Chrome 30, Safari 11.1, Edge 14, but not on most mobile browsers as of 2019: https://caniuse.com/#feat=input-file-directory

    0 讨论(0)
提交回复
热议问题