Is it possible to upload a Folder using HTML Form / PHP script

烂漫一生 提交于 2019-12-05 12:36:28

It is possible to upload a folder now. You can get it done by following below code:

  <input type="file" webkitdirectory mozdirectory />

You can check the demo here: https://jsfiddle.net/kevalpadia/vk6Ldzae/

I hope it will help you solve your issue.

CS GO

The Current Answer is NOT supported by all browsers.

You can not upload a whole folder.

currently only chrome supports it

And to upload many files http://www.uploadify.com/

<input type="file" webkitdirectory="" directory="" /> - this works just on few/modern browsers- like Edge or Webkit engines (Chrome). I think that is not supported by Firefox.

You can use HTML5's

<input type="file" multiple>

About processing uploads in PHP, read more here: http://php.net/manual/en/features.file-upload.post-method.php

Give this PHP script a go:

Main website: http://www.uploadify.com/

Documentation: http://www.uploadify.com/documentation/

Yes, It is possible. Here is the code:

<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

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!!";
}
?>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!