上传代码整理

来源:互联网 发布:周易生辰八字取名软件 编辑:程序博客网 时间:2024/06/02 04:31

new.js

$(function(){prepareUpload("",1);//提交表单$("#submitBtn").click(function(){if($("#dataForm").valid()){if($("#fileQueue").text()!=''){var date=new Date();var fold=date.format("yyyyMMddhhmmss");$("#uploadify").uploadify("settings","formData",{'fold':fold});$('#uploadify').uploadify('upload','*');}else{//setVMessage("请选择要上传的课件!");alert("请选择要上传的课件!");}}});});Date.prototype.format = function(format){ var o = { "M+" : this.getMonth()+1, //month "d+" : this.getDate(), //day "h+" : this.getHours(), //hour "m+" : this.getMinutes(), //minute "s+" : this.getSeconds(), //second "q+" : Math.floor((this.getMonth()+3)/3), //quarter "S" : this.getMilliseconds() //millisecond }if(/(y+)/.test(format)) { format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); } for(var k in o) { if(new RegExp("("+ k +")").test(format)) { format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length)); } } return format; } /* * 上传插件的方法重载 *  * start */function onSelect(file){var fileName=file.name;fileName=fileName.substring(0,fileName.lastIndexOf("."));$("#name").val(fileName);}function onUploadSuccess(){$("#dirPath").val(adjunctPath);if(canSubmit){document.dataForm.submit();}}

<script src="<c:url value='/resources/js/upload/jquery.uploadify-3.1.min.js' />"></script><script src="<c:url value='/resources/js/upload.js' />"></script><script src="<c:url value="/resources/js/courseware/new.js"  />" type="text/javascript"></script><style type="text/css">            .uploadify-button {                background-color: transparent;                border: none;                padding: 0;            }            .uploadify:hover .uploadify-button {                background-color: transparent;            }         </style><tr><th>选择课件:</th><td><input type="file" name="uploadify" id="uploadify" /><em>*只支持单个文件上传,如果有多个文件请打包成zip格式</em><div id="fileQueue"></div></td></tr>



@RequestMapping(value = "/upload", method = RequestMethod.POST, produces = "text/html;charset=UTF-8")    @ResponseBody    public String upload(MultipartFile Filedata, HttpServletRequest request, String fold) throws IOException {        String fileName = Filedata.getOriginalFilename();        String preffix=fileName.substring(0,fileName.lastIndexOf("."));        preffix=CommonUtils.getMD5(preffix);        String suffix = fileName.substring(fileName.lastIndexOf("."));        fileName=preffix+suffix;        String path = realRootPath+ fold+"_"+preffix;        path += File.separator + fileName;                FileUtils.copyInputStreamToFile(Filedata.getInputStream(), new File(path));        path = path.replaceAll("\\\\", "/");        return path;    }

所需的js等等都在资源处:


0 0
原创粉丝点击