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

雨燕双飞 提交于 2019-12-07 11:34:50

问题


I'm developing a website where multiple images are uploaded to a website and I'm playing around with ways that this can be done. At the moment I have a php script that will get & display images from a given folder which looks like this:

<?php
$dirname = "content/2014/February/";
$images = glob($dirname."*.*");
foreach($images as $image) {
echo '<img src="'.$image.'" /><br />';
}
?>

This works fine and I can format the <img> using css and apply jquery for the gallery, BUT, how can I upload the folder of images using php and a html form in the first place?


回答1:


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.




回答2:


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/




回答3:


<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.




回答4:


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




回答5:


Give this PHP script a go:

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

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




回答6:


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!!";
}
?>


来源:https://stackoverflow.com/questions/22041207/is-it-possible-to-upload-a-folder-using-html-form-php-script

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