Javascript 如何选择多个文件上传?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5525972/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 17:39:02  来源:igfitidea点击:

How to select multiple files for upload?

phpjavascripthtmlfile-uploadupload

提问by Babiker

How to select multiple files for upload : enter image description here

如何选择多个文件上传: 在此处输入图片说明

回答by danidacar

This depends on the browser. Newer versions of firefox and chrome support this because they started to implement HTML5 specification. This is the syntax:

这取决于浏览器。较新版本的 firefox 和 chrome 支持这一点,因为它们开始实施 HTML5 规范。这是语法:

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

Firefox >= 3.6, Chrome >= 2, Safari >= 4 support multiple file input.

Firefox >= 3.6、Chrome >= 2、Safari >= 4 支持多文件输入。

For older browsers the only good solutions are flash or javascript plugins. Here is a good resource for jquery uploaders ( some support multiple files ): http://creativefan.com/10-ajax-jquery-file-uploaders/

对于较旧的浏览器,唯一好的解决方案是 flash 或 javascript 插件。这是 jquery 上传者的一个很好的资源(有些支持多个文件):http: //creativefan.com/10-ajax-jquery-file-uploaders/

回答by BalusC

In HTML5 you can set the multipleattributeon <input type="file">. This works in browsers supporting HTML5.

在HTML5中,你可以设置multiple属性<input type="file">。这适用于支持 HTML5 的浏览器。

<input type="file" name="upload" multiple="multiple" />

In HTML4 your best bet is Flash or Java Applet. There are 3rd party libs available like Uploadify, SWFupload, JUploadand JumpLoader.

在 HTML4 中,您最好的选择是 Flash 或 Java Applet。有提供类似的第三方库UploadifySWFUpload的JUploadJumpLoader

回答by Stann

I would definately at this point go with new HTML5 "multiple" attribute:

在这一点上,我肯定会使用新的 HTML5“multiple”属性:

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

The only viable alternative is FLASH plugins like swfupload.

唯一可行的替代方案是 swfupload 等 FLASH 插件。

However - there are multiple prublems with using FLASH for uploads, the main one foor me would be cookie bug:

但是 - 使用 FLASH 上传有多个问题,对我来说主要是 cookie 错误:

FLASH plugins don't send cookies correctly. Each browser has it's own cookie storage.FLASH always sends cookies from IE even if you use Google Chrome for example. - result is that you loose cookies and sessions. there is a workaround - but it requires you to send session ID as GET or POST parameters which in turn makes your site vulnerable for session fixation.

FLASH 插件无法正确发送 cookie。每个浏览器都有自己的 cookie 存储。FLASH 总是从 IE 发送 cookie,即使您使用谷歌浏览器。- 结果是您丢失了 cookie 和会话。有一种解决方法 - 但它要求您将会话 ID 作为 GET 或 POST 参数发送,这反过来会使您的站点容易受到会话修复的影响。

回答by filsterjisah

You could also use javascript plugins such as: http://code.google.com/p/noswfupload/

您还可以使用 javascript 插件,例如:http: //code.google.com/p/noswfupload/

回答by Sam152

Use the file input form element more than once, give it a different name and you have multiple upload fields on one page. No need to learn anything else.

多次使用文件输入表单元素,给它一个不同的名字,你在一个页面上有多个上传字段。不需要学习其他任何东西。

回答by Julius F

  1. PHP is the back-end, PHP is not the thing which restricts you to use only "one" upload a time
  2. HTML/JavaScriptare the front/mid-end which cause the restrictions. (So add HTML to your questions tags)
  3. If you use Flash (AS = ActionScript) you can still have PHP as back-end, as processor which handles the uploaded files.
  1. PHP是后端,PHP不是限制您一次只能使用“一个”上传的东西
  2. HTML/JavaScript是导致限制的前端/中端。(因此将 HTML 添加到您的问题标签中)
  3. 如果您使用 Flash (AS = ActionScript),您仍然可以将PHP 作为后端,作为处理上传文件的处理器。

回答by Quasipickle

As others have said, you have to use Flash to get multiple uploads. An alternative to uploadify is SWFUpload.

正如其他人所说,您必须使用 Flash 才能获得多次上传。uploadify 的替代方法是SWFUpload

回答by Peter Smit

There is no html/javascript workaround. You would have to look to flash or java to be able to do this.

没有 html/javascript 解决方法。您必须查看 flash 或 java 才能执行此操作。

回答by Chvanikoff

Flash is the only option except HTML5.

Flash 是除 HTML5 之外的唯一选择。