| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
jopen
9年前发布

JQuery上传插件Uploadify使用详解

1:准备工作

      官方下载地址: http://www.uploadify.com/download/
2:引入文件
<link href="uploadify.css" rel="stylesheet">           
<script src="jquery.uploadify.min.js"></script>
</div> </pre></div>

</div>

3:前台页面
<input type="hidden" id="filepathInput" />           
<input type="file" id="btnUploadify" name="uploadify" />
<div id="show_back"></div>
</div> </pre></div>

</div>

4:初始化控件
 function initUploadify() {        $("#btnUploadify").uploadify({            height: 30,            swf: "uploadify.swf",            cancelImage: "uploadify-cancel.png",            uploader: 'common/op/uploadFileForMedia.shtml?type=video',            fileTypeDesc: '视频类型',            fileTypeExts: '*.mp4',            width: 100,            multi: false,            fileSizeLimit : '10MB', //设置单个文件大小限制             method: 'post',            fileObjName: 'uploadify',            buttonText: "选择文件",            onUploadSuccess: function (file, data, response) {                //上传成功                if (response) {                 var dataJson = eval("(" + data + ")");                 $("#filepathInput").val(dataJson.filePath);                 var html = '<video controls=controls autoplay=autoplay> '            +'<source src="'+ dataJson.basepath + "\/" + dataJson.filename+'" type="video/mp4" />'            +'</video>';                 $("#show_back").html(html);                }            },            onUploadError : function(file,errorCode,errorMsg,errorString,swfuploadifyQueue) {                               },            auto: true            });    }      

5:后台代码
public class FileUploadAction extends BaseAction {      private File uploadify;   private String uploadifyFileName;      public String uploadFile() throws Exception {    map = new HashMap<String, Object>();    // 上传完后文件存放位置    String savePath = getRealPath() + "upload";    System.out.println(savePath);    String newsuffix = "";    String current = UUID.randomUUID().toString();    if ((uploadifyFileName != null) && (uploadifyFileName.length() > 0)) {     int dot = uploadifyFileName.lastIndexOf(".");     if ((dot > -1) && (dot < (uploadifyFileName.length() - 1))) {      newsuffix = uploadifyFileName.substring(dot + 1);     }    }    FileInputStream fis = null;    FileOutputStream fos = null;    try {     fis = new FileInputStream(uploadify);     String serPath = savePath + File.separatorChar + current + "."       + newsuffix;     fos = new FileOutputStream(serPath);     IOUtils.copy(fis, fos);     map.put("filename", current + "." + newsuffix);     map.put("basepath", "upload/");    } catch (Exception e) {     e.printStackTrace();    } finally {     if (fos != null) {      fos.flush();      fos.close();     }     if (fis != null) {      fis.close();     }    }    return "toResult";   }        }

</div>

 本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!