是否可以使用 HTML 表单 / PHP 脚本上传文件夹
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22041207/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is it possible to upload a Folder using HTML Form / PHP script
提问by user3177012
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 脚本,可以从给定的文件夹中获取和显示图像,如下所示:
<?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?
这很好用,我可以格式化<img>使用 css 并将 jquery 应用于图库,但是,我如何首先使用 php 和 html 表单上传图像文件夹?
回答by Nimblechapps
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/
您可以在此处查看演示:https: //jsfiddle.net/kevalpadia/vk6Ldzae/
I hope it will help you solve your issue.
我希望它能帮助你解决你的问题。
回答by CS GO
The Current Answer is NOTsupported by all browsers.
并非所有浏览器都支持当前答案。
You can not upload a whole folder.
您不能上传整个文件夹。
currently only chrome supports it
And to upload many files http://www.uploadify.com/
并上传许多文件http://www.uploadify.com/
回答by Boris Delev
<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.
<input type="file" webkitdirectory="" directory="" />- 这仅适用于少数/现代浏览器 - 如 Edge 或 Webkit 引擎 (Chrome)。我认为 Firefox 不支持。
回答by Ratnesh
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!!";
}
?>
回答by kazy
You can use HTML5's
您可以使用 HTML5
<input type="file" multiple>
About processing uploads in PHP, read more here: http://php.net/manual/en/features.file-upload.post-method.php
关于在 PHP 中处理上传,请在此处阅读更多信息:http: //php.net/manual/en/features.file-upload.post-method.php
回答by Vrutin Rathod
Give this PHP script a go:
试试这个 PHP 脚本:
Main website: http://www.uploadify.com/
主网站:http: //www.uploadify.com/
Documentation: http://www.uploadify.com/documentation/

