随笔-46  评论-54  文章-0  trackbacks-0
 

参考了这篇the script is not working for any mvc frameworkuri的回复,结合当前Uploadifyv2.1.4版,netbean 6.9.1下编写调试。

        新建grails工程,名为test,并把Uploadify-v2.1.4.zip解压到web-app\uploadify目录下。

        新建grails控制器PictureController,代码如下

package com.test

 

class PictureController {

 

    def index = { redirect(action: "upload") }

 

    def upload = { }

 

    def savePicture = {

       def files = request.getFileMap();

       def path = "c:/test/" + files.get("Filedata").getOriginalFilename();

       files.get("Filedata").transferTo( new File(path))

       render (view:'upload')

    }

}

        新建grails视图upload.gsp,代码如下,注意粗体部分的上下文路径

<html>

  <head>

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <title>upload file sample</title>

    <link rel="stylesheet" href="/test/uploadify/uploadify.css" type="text/css" />

    <script type="text/javascript" src="/test/uploadify/jquery-1.4.2.min.js"></script>

    <script type="text/javascript" src="/test/uploadify/swfobject.js"></script>

    <script type="text/javascript" src="/test/uploadify/jquery.uploadify.v2.1.4.min.js"></script>

    <script type="text/javascript">

    $(document).ready(function() {

            $("#fileUpload").uploadify({

                'uploader': '/test/uploadify/uploadify.swf',

              'cancelImg': '/test/uploadify/cancel.png',

              'script': '/test/picture/savePicture',

              'folder': 'files',

              'multi': true,

              'buttonText': 'add',

              'displayData': 'speed',

              'simUploadLimit': 2

            });

    });

    </script>

  </head>

  <body>

    <hr width=100% size="1" color="" align="center">

        <h2>Multiple File Upload</h2>

        <p>checkScript, buttonText, simulataneous upload limit</p>

        <div id="fileUpload">You have a problem with your javascript</div>

        <a href="javascript:$('#fileUpload').uploadifyUpload()">Start Upload</a> |  <a href="javascript:$('#fileUpload').uploadifyClearQueue()">Clear Queue</a>

<p></p>

  </body>

</html>

        运行工程,访问http://localhost:8080/test/picture/upload

posted on 2010-12-06 15:38 rox 阅读(1071) 评论(2)  编辑  收藏

评论:
# re: Grails结合Uploadify上传文件的简单代码 2014-03-28 10:25 | 陈丽
这是一篇很棒的帖子,在这篇文章的基础傻姑娘进行修改和改进,完成了我想要的功能,真的很不错  回复  更多评论
  
# re: Grails结合Uploadify上传文件的简单代码 2014-03-28 10:29 | rox
@陈丽
谬夸了,只要能帮助到大家就好。  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: