首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Rook上传多个文件

使用Rook上传多个文件
EN

Stack Overflow用户
提问于 2011-06-27 01:08:00
回答 1查看 660关注 0票数 6

HTML5规范允许通过<input type="file", ..., multiple="multiple">一次上传多个文件。有没有办法在Rook R包中利用这一点?

这是我的尝试,但它似乎只显示了所选文件中的一个:

代码语言:javascript
复制
library(Rook)

app <- function(env) {
  req <- Rook::Request$new(env)
  res <- Rook::Response$new()
  res$write(
   '<html><body>
      Select files:
      <form method="POST" enctype="multipart/form-data">
        <input type="file" name="data" multiple="multiple">
        <input type="submit" name="Upload">
      </form>
    </body></html>')

  if (!is.null(req$POST())){
    data <- req$POST()[['data']]
    res$write("<pre>")
    res$write(paste(capture.output(req$POST(),file=NULL),collapse='\n'))
    res$write("</pre>")
    res$write("<pre>")
    res$write(paste(capture.output(data$filename,file=NULL),collapse='\n'))
    res$write("</pre>")
  }
  res$finish()
}

s <- Rhttpd$new()
s$add(app=RhttpdApp$new(name="app", app=app))
s$start(listen="127.0.0.1", quiet=FALSE)
s$browse(1)

#s$stop(); s$remove(all=TRUE); rm(s)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-06-27 23:22:00

目前还不完全支持该规范;我刚刚在Chrome12.0.742.100上试过,浏览器界面甚至不允许选择多个文件。

要上传多个文件,您需要创建多个输入元素,如下所示:

代码语言:javascript
复制
<input type="file" name="file1">...
<input type="file" name="file2">...
...
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6485401

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档