隨筆-167  評論-65  文章-0  trackbacks-0
          最近在做圖片的上傳,但是客戶可以在上傳之前對自己的圖片進(jìn)行剪切,本想讓圖片不上傳到server上就可以剪切的,但是最后在firefox上遇到了麻煩,firefox中不可以得到input type=file的全路徑,只可以得到文件名,很讓人郁悶。。。google了下,網(wǎng)上有好多人遇到了這個問題,說是firefox從安全考慮的,不管它了。。估計(jì)肯定有解決辦法,找到了一個別人實(shí)現(xiàn)的。。但是預(yù)覽功能都是用js輸出的,我要用image 標(biāo)簽輸出,改這個js也不簡單:
          http://hedgerwow.appspot.com/image-upload-preview/demo.html
          我也就沒有繼續(xù)折騰,最后參照xiaonei的圖片上傳 剪切功能辦法,實(shí)現(xiàn)了,其實(shí)就是先把圖片上傳到server上的。。。
          xiaonei 網(wǎng)址:http://head.upload.xiaonei.com/Upload.do
          沒有xiaonei號的。。看我的一張截圖吧。。其實(shí)也就是多了一個上傳button罷了



          我的效果:

          核心代碼:
          rhtml:
            <form name="uploadform" id="uploadform" action="crop" method="post" enctype="multipart/form-data">
           <input id="uploadimage" type="file" name="uploadimage"/>
          <input type="submit" class="button" name="upload" value="上傳" id="upload" />
          </form>


          controller:
              if params[:upload]
                image = params[:uploadimage]
                name = image.original_filename
                File.makedirs("public/upload/tmp")
                directory = "public/upload/tmp"
                path = File.join(directory,name)  
                File.open(path, "wb") { |f| f.write(image.read) } # important
                @src = path[6..-1] # get image src
              end

          source download:
          http://www.uushare.com/user/fl1429/file/1842295   (ruby1.8.6 + rails 2.1.0)


          write by feng
          posted on 2009-06-22 18:11 fl1429 閱讀(550) 評論(0)  編輯  收藏 所屬分類: Rails
          已訪問數(shù):
          free counters
          主站蜘蛛池模板: 锡林郭勒盟| 桂东县| 大邑县| 双流县| 临海市| 木兰县| 射洪县| 开化县| 新化县| 德钦县| 玉龙| 浮山县| 平顶山市| 天峻县| 博湖县| 台北市| 南投市| 当雄县| 肥城市| 沈丘县| 保康县| 怀宁县| 交口县| 揭阳市| 海安县| 福海县| 九江县| 庆城县| 临颍县| SHOW| 万载县| 鄯善县| 大港区| 南城县| 丰都县| 柯坪县| 木兰县| 潞城市| 太仆寺旗| 登封市| 汶上县|