---
title: "关于多个文件上传"
author: "jackdraw"
date: "2007-07-21T10:00:15Z"
tags: []
slug: "untitled"
draft: false
lastmod: "2007-07-21T10:00:15Z"
id: 103720
url: "https://jackdraw.iteye.com/blog/103720"
---

上传多个文件上传参阅了

[http://the-stickman.com/web-development/javascript/upload-multiple-files-with-a-single-file-element/](http://the-stickman.com/web-development/javascript/upload-multiple-files-with-a-single-file-element/)

[http://www.flex888.com/2007/03/23/multiple-file-upload-with-ruby-on-rails-acts\_as\_attachment.html](http://www.flex888.com/2007/03/23/multiple-file-upload-with-ruby-on-rails-acts_as_attachment.html)

[http://www.flex888.com/2007/03/23/multiple-file-upload-with-ruby-on-rails-acts\_as\_attachment.html](http://www.flex888.com/2007/03/23/multiple-file-upload-with-ruby-on-rails-acts_as_attachment.html)

其本上以最下面的为主，我主要用RMagick ，filecolumn，然后是上面连接中的 cool multiple file upload JavaScript 下面是是上面文章中的一段截取

First of all, go [here](http://the-stickman.com/web-development/javascript/upload-multiple-files-with-a-single-file-element/) to [download](http://the-stickman.com/web-development/javascript/upload-multiple-files-with-a-single-file-element/) the cool multiple file upload JavaScript so that you can have the dynamic file list built up for uploading, like this:

[![](http://i53.photobucket.com/albums/g67/moxiezhang/flex888/multiplefileuploadwithrubyonrailsActs_as_14574/multiplefileul_thumb1.jpg)](http://i53.photobucket.com/albums/g67/moxiezhang/flex888/multiplefileuploadwithrubyonrailsActs_as_14574/multiplefileul3.jpg)

根据上面的提示下载好uplad javascript

放在自己的工程里，关于rmargick,filecolumn文件上传的搭配参考再建rmargick filecoumn一文，网上也比较多，

好了之后在view中加入

java 代码

1. "my\_file\_element" type="file" name="file\_1" &gt;
2. #在controller中加入
3. i = 0  
       while @params\["file\_"+i.to\_s] != "" and i &lt;=2  
          p = Hash\["entry"=&gt;{"image"=&gt;""}]  
           p\["entry"]\["image] = params\["file\_"+i.to\_s] if i != 0  
          @entry = Entry.create!(p\["entry"])  
         i += 1  
       end  
   就可以了，就可以实件文件上传了
4. 如果你要一表多字段的话只要修改上面的代码就可以了，然后在 entry中
5. file\_column :image, :magick =&gt; {     
       :versions =&gt; { "thumb" =&gt; "50x50", "medium" =&gt; "640x480&gt;" }    
     }   
      file\_column :image1, :magick =&gt; {     
       :versions =&gt; { "thumb" =&gt; "50x50", "medium" =&gt; "640x480&gt;" }    
     }
6. 增加相应的字段就可以了

 

此文多半属于抄阅，记下以便学习，请参考上面连接

关于如何使用file column 请参考

http://wiki.rubyonrails.org/rails/pages/HowToUseFileColumn