隨筆-167  評(píng)論-65  文章-0  trackbacks-0
          rails中把文件上傳到文件夾中,一般有圖片,rar文件等等,試著找了些rails file upload的plugins (fleximage,attachment_fu,paperclip.....),但是最后發(fā)現(xiàn)都不是太好用,最后利用原始ruby api實(shí)現(xiàn)了,實(shí)現(xiàn)步驟:

          rhtml:
              <form name="photo" enctype="multipart/form-data" action="/upload/path" method="post">
              Photo <input type="file" name="image"  id="image" size="30"  />
              <input type="submit" name="upload" value="Upload"  class="button" />
              </form>

          controller:
          path = 'public/data'
          File.open(path, "wb") { |f| f.write(params[:image].read) }

          that's all,簡(jiǎn)單吧。。注意在用File類(lèi)的一些方法時(shí),需要require 'ftools'

          ref:
          http://www.tutorialspoint.com/ruby-on-rails-2.1/rails-file-uploading.htm



          write by feng
          posted on 2009-06-19 19:19 fl1429 閱讀(837) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): Rails
          已訪問(wèn)數(shù):
          free counters
          主站蜘蛛池模板: 育儿| 江陵县| 越西县| 巨鹿县| 溧水县| 元江| 信阳市| 涡阳县| 图片| 磐石市| 华安县| 上犹县| 无棣县| 彭阳县| 隆化县| 平山县| 房产| 禄丰县| 托里县| 怀柔区| 高阳县| 盐亭县| 新泰市| 永安市| 宕昌县| 额济纳旗| 陆良县| 永吉县| 姚安县| 抚顺县| 峨山| 佛冈县| 松桃| 南平市| 拜城县| 宁夏| 错那县| 甘南县| 即墨市| 象州县| 饶平县|