我怎样才能从相同的输入类型上传文件夹和文件? [英] How can I upload folder and files both from same input type?

查看:86
本文介绍了我怎样才能从相同的输入类型上传文件夹和文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的表单可以同时上传文件或完整文件夹。我使用以下代码:

 < html> 
< input type =fileid =filename =files []multiple />
< input id =filetype = file multiple webkitdirectory directory>
< / html>

通过第一次输入,我可以上传文件,但不能上传文件夹和第二个输入,我可以上传文件夹,但不是文件。但我希望能够以相同的输入上传两个文件。



请告诉我什么是我可以单击一次就可以上传文件和文件夹的确切代码。 / p>当我写这篇文章的时候,这对纯HTML来说是不可能的,除非你使用一些像Flash这样的插件,那么也许这是可能的

<1>文件上传:


 < input type =文件name =file> 

多个文件上传(但必须位于同一个文件夹中):

 < input type =filename =file []multiple> 

1个文件夹上传(注意:并非所有浏览器都支持此功能):

 < input type =filename =filewebkitdirectory directory> 

目前可能无法上传多个文件夹。



这可能有用(但我没有测试它)的技巧:您可以直接在输入字段中拖放文件和文件夹,例如从桌面到浏览器的输入。尝试选择文件和文件夹并将它们在输入字段中进行drog-n-drop,但我不知道它们是否会正确上传到服务器。



编辑:



刚刚测试过这个技巧,它不起作用:/ b / b

I am using a form where I can upload both, a file or full folder. I am using following code:

<html>
  <input type = "file" id = "file" name = "files[]" multiple/>
  <input id="file" type=file multiple webkitdirectory directory>
</html>

With first input, I can upload file but not folder and with 2nd input, I can upload folder but not file. But I want to be able to upload both with same input.

Please tell me what is the exact code by which I can upload both file and folder in single click.

解决方案

As I'm writing this, this is not possible with pure HTML, unless you use some plugin like Flash then maybe it's possible.

1 file upload:

<input type="file" name="file">

Multiple files upload (but must be in same folder):

<input type="file" name="file[]" multiple>

1 folder upload (Note: not all browsers may support this):

<input type="file" name="file" webkitdirectory directory>

Multiple folders upload maybe not possible currently.

Here is a trick that might work (but I didn't test it): You can drag and drop file(s) and folder(s) directly in the input field, for example from your desktop to the browser's input. Try selecting files AND folders and drog-n-drop them in your input field, but I don't know if they will be uploaded correctly to the server.

EDIT:

Just tested that trick, it didn't work :/

这篇关于我怎样才能从相同的输入类型上传文件夹和文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆