我正在尝试使用一个文件输入元素将多个文件上传到使用html表单的Drive。这似乎只适用于一个文件,尽管文件选择器允许选择多个文件。回到脚本日志查看器,我只看到我上传的两个文件中的一个。这是不受支持的,还是我走错了路?
Code.gs:
function logForm(form) {
Logger.log(JSON.stringify(form));
return true;
}
index.html:
<html>
<form id="uploadTest" enctype="multipart/form-data">
<input type="file" multiple="multiple" name="fileUpload">
<input type="button" id="upload" value="upload"
onclick="google.script.run.logForm(document.getElementById('uploadTest'));">
</form>
</html>
日志视图:
{"fileUpload":{"contents":"GIF87a\u0001\u0000\u0001\u0000�
\u0000\u0000��̖��,\u0000\u0000\u0000\u0000\u0001\u0000
\u0001\u0000\u0000\u0002\u0002D\u0001\u0000;",
"type":"image/gif","name":"1x1.gif","length":35}}
发布于 2013-04-03 12:35:02
当您单击文件字段的浏览按钮时,对话框中的多个文件选择仅适用于new browsers supporting HTML5。它将不允许对旧浏览器进行多次选择。对于较老的浏览器,唯一好的解决方案是flash或javascript插件。这里有一个很好的资源给jquery上传者(有些支持多个文件):http://creativefan.com/10-ajax-jquery-file-uploaders/。因此,我的建议是使用一些插件,以便在旧浏览器和新浏览器上都支持它。
发布于 2015-08-26 15:13:45
我正在使用可能性来发送文件数组。只需将[]
添加到名称属性:
<form action="/" enctype="multipart/form-data" method="post">
<input type="file" name="files[]" />
<input type="file" name="files[]" />
// etc.
<input type="submit">
</form>
您将在$_FILES
中拥有数组
Array
(
[files] => Array
(
[name] => Array
(
[0] => 1.png
[1] => 2.png
)
[type] => Array
(
[0] => image/png
[1] => image/png
)
[tmp_name] => Array
(
[0] => /tmp/phpDQOZWD
[1] => /tmp/phpCELeSw
)
[error] => Array
(
[0] => 0
[1] => 0
)
[size] => Array
(
[0] => 32209
[1] => 64109
)
)
)
当然,你你必须一个接一个地上传。对大量文件不方便,但适用于所有浏览器。例如,使用jQuery,您可以在每次更改最后一个files[]
输入时再添加一个输入。
function addOneMoreInput() {
$('input[type=file]').last().change(function() {
$(this).after('<input type="file" name="files[]" />');
$(this).off('change');
addOneMoreInput();
});
}
addOneMoreInput();
https://stackoverflow.com/questions/15726439
复制相似问题