2011-06-26 60 views
6

HTML5规范允许通过<input type="file", ..., multiple="multiple">立即上传多个文件。有没有办法利用Rook R包的优势?使用Rook上传多个文件

这里是我的尝试,但它似乎只显示所选择的文件之一:

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) 
+0

嗯...你可能想送这鲁克邮件列表。我知道可以用RApache上传多个文件。 – aL3xa

回答

4

该规范不完全支持尚未;我刚刚尝试过Chrome 12.0.742.100,浏览器界面甚至不允许选择多个文件。

要上传你将要创建多个输入元素,像这样多个文件:

<input type="file" name="file1">... 
<input type="file" name="file2">... 
... 
+0

感谢您的回答。我能够使用Firefox 4.x选择多个文件,但我没有在Rook环境中看到它们。 –