<script src="${base}/thirdparty/swfupload/swfupload.js" type="text/javascript"></script> <script src="${base}/thirdparty/swfupload/swfupload.queue.js" type="text/javascript"></script> <script src="${base}/thirdparty/swfupload/fileprogress.js" type="text/javascript"></script> <script src="${base}/thirdparty/swfupload/handlers.js" type="text/javascript"></script> <link href="${base}/thirdparty/swfupload/process.css" rel="stylesheet" type="text/css"/>
<#include "/common/image_upload.html"/>
<@e.text label="认证通过图标" id="uploadImgPath1" class="dfinput" name="icon" readonly="readonly"/> <@e.text label="图片路径" id="uploadFileText1" size="14" class="dfinput" /> <input type="file" id="uploadFile1" size="14" onchange="$('#uploadFileText1').val(this.value)"/> <br/> <@e.hidden id="mark1" value="false"/> <@e.button class="upload-button" onclick="upload(1);" value="上传"/> <br/> <a title="标题图1" id="preBigImg1" class="cmcss" href="${base}/${(mmiGroupBanner1)!}" style="margin-left:87px;margin-top:10px;" > <img id="preImg1" style="width:100px;height:70px;background-color:#CCCCCC;" maxWidth2="200" /> </a> <@e.text label="认证不通过图标" id="uploadImgPath2" class="dfinput" name="xicon" readonly="readonly"/> <@e.text label="图片路径" id="uploadFileText2" size="14" class="dfinput" /> <input type="file" id="uploadFile2" size="14" onchange="$('#uploadFileText2').val(this.value)"/> <br/> <@e.hidden id="mark1" value="false"/> <@e.button class="upload-button" onclick="upload(2);" value="上传"/> <br/> <a title="标题图2" id="preBigImg2" class="cmcss" href="${base}/${(mmiGroupBanner2)!}" style="margin-left:87px;margin-top:10px;" > <img id="preImg2" style="width:100px;height:70px;background-color:#CCCCCC;" maxWidth2="200" /> </a>
package cn.com.yhxl.jhahi.action.admin; import java.util.Locale; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.io.FilenameUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.multipart.MultipartFile; import cn.com.yhxl.basic.entity.ms.MsSystemConfig; import cn.com.yhxl.basic.service.ms.IMsSystemConfigService; import cn.com.yhxl.common.upload.FileRepository; @Controller public class FileUploadAct { private static final Logger log = LoggerFactory.getLogger(FileUploadAct.class); private static final String RESULT_PAGE = "/common/iframe_upload"; @RequiresPermissions("file:swfupload") @RequestMapping(value = "/file/o_swfupload.do", method = RequestMethod.POST) public String swfAttachsUpload(String root,Integer uploadNum, @RequestParam(value = "uploadFile", required = false) MultipartFile file,HttpServletRequest request, HttpServletResponse response,ModelMap model) throws Exception { MsSystemConfig sc = scService.get(); String origName = file.getOriginalFilename(); String ext = FilenameUtils.getExtension(origName).toLowerCase(Locale.ENGLISH); String fileUrl = ""; try { if(ext.equalsIgnoreCase("flv") || ext.equalsIgnoreCase("mp4") || ext.equalsIgnoreCase("f4v")){ fileUrl = fileRepository.storeByExtVideo(sc.getScVideoUploadPath(), ext, file); fileUrl = fileUrl.replace(sc.getScVideoUploadPath(), sc.getScVideoPrefixUrl()); }else if(ext.equalsIgnoreCase("bmp") || ext.equalsIgnoreCase("png") || ext.equalsIgnoreCase("jpg") || ext.equalsIgnoreCase("jpeg")){ fileUrl = fileRepository.storeByExt(sc.getScPhotoUploadPath(), ext, file); }else{ fileUrl = fileRepository.storeByExt(sc.getScFileUploadPath(), ext, file); } // 加上部署路径 //System.out.println("fileUrl="+fileUrl); //fileMng.saveFileByPath(fileUrl, origName, false); model.addAttribute("attachmentPath", fileUrl); model.addAttribute("uploadPath", fileUrl); model.addAttribute("uploadNum", uploadNum); return RESULT_PAGE; } catch (Exception e) { log.error("文件上传发生错误", e); model.addAttribute("error", e.getMessage()); } return RESULT_PAGE; } @Autowired protected FileRepository fileRepository; @Autowired private IMsSystemConfigService scService; }
前台上传
修改<#include "/common/image_upload.html"/>文件
<script type="text/javascript"> //上传图片 function upload(n) { var of = $("#uploadFile"+n); //检查是否选择了图片 if(of.val()=="") { alert("<@s.m "imageupload.error.noFileToUpload"/>"); return; } //将file移动至上传表单 $("#fileContent").empty(); $("#fileContent").append(of); //复制一个file放至原处 $("#ufc"+n).append(of.clone().attr("value","")); //修改属性 $("#uploadFileText"+n).attr("value",""); of.attr("id",""); of.attr("name","uploadFile"); //其他表单 $("#ufFileName").val($("#fileName"+n).val()); $("#ufWidth").val($("#zoomWidth"+n).val()); $("#ufHeight").val($("#zoomHeight"+n).val()); //先清除 $("#ufMark").val(""); $("#ufMark").val($("#mark"+n).val()); $("#uploadNum").val(n); $("#uploadForm").submit(); } //剪裁图片 function imgCut(n) { if($("#uploadImgPath"+n).val()=="") { alert("<@s.m "imageupload.error.noFileToCut"/>"); return; } var url = "../common/v_image_area_select.do?uploadNum="+n+"&imgSrcPath=" +$("#uploadImgPath"+n).val()+"&zoomWidth="+$("#zoomWidth"+n).val()+"&zoomHeight="+$("#zoomHeight"+n).val(); window.open(url,"imgcut","height=550, width=1000, top=0, left=0, toolbar=no, menubar=no, scrollbars=auto, resizable=yes,location=no, status=no"); } //预览图片 function previewImg(n) { var img = $("#uploadImgPath"+n).val(); if(img!="") { if(img.indexOf("?")==-1) { $("#preImg"+n).attr("src",img+"?d="+new Date()*1); } else { $("#preImg"+n).attr("src",img+"&d="+new Date()*1); } if(!$("#preImg"+n).attr("noResize")) { $("#preImg"+n).css("width","auto"); $("#preImg"+n).css("height","auto"); } } else { $("#preImg"+n).removeAttr("src"); } } </script> <form id="uploadForm" action="../doctor/o_swfupload.jhtml" method="post" enctype="multipart/form-data" target="hiddenIframe" style="display:none;width:0px;height:0px;"> <span id="fileContent"></span> <input id="ufWidth" type="hidden" name="zoomWidth"/> <input id="ufHeight" type="hidden" name="zoomHeight"/> <input id="ufFileName" type="hidden" name="fileName"/> <input id="ufMark" type="hidden" name="mark"/> <input id="uploadNum" type="hidden" name="uploadNum"/> </form> <iframe name="hiddenIframe" frameborder="0" border="0" style="display:none;width:0px;height:0px;"></iframe>
@RequestMapping(value = "/o_swfupload.jhtml", method = RequestMethod.POST) public String swfAttachsUpload(String root,Integer uploadNum, @RequestParam(value = "uploadFile", required = false) MultipartFile file,HttpServletRequest request, HttpServletResponse response,ModelMap model) throws Exception { MsSystemConfig sc = scService.get(); String origName = file.getOriginalFilename(); String ext = FilenameUtils.getExtension(origName).toLowerCase(Locale.ENGLISH); String fileUrl = ""; try { if(ext.equalsIgnoreCase("flv") || ext.equalsIgnoreCase("mp4") || ext.equalsIgnoreCase("f4v")){ fileUrl = fileRepository.storeByExtVideo(sc.getScVideoUploadPath(), ext, file); fileUrl = fileUrl.replace(sc.getScVideoUploadPath(), sc.getScVideoPrefixUrl()); }else if(ext.equalsIgnoreCase("bmp") || ext.equalsIgnoreCase("png") || ext.equalsIgnoreCase("jpg") || ext.equalsIgnoreCase("jpeg")){ fileUrl = fileRepository.storeByExt(sc.getScPhotoUploadPath(), ext, file); }else{ fileUrl = fileRepository.storeByExt(sc.getScFileUploadPath(), ext, file); } // 加上部署路径 //System.out.println("fileUrl="+fileUrl); //fileMng.saveFileByPath(fileUrl, origName, false); model.addAttribute("attachmentPath", fileUrl); model.addAttribute("uploadPath", fileUrl); model.addAttribute("uploadNum", uploadNum); // return RESULT_PAGE; return FrontUtils.getTplPathUrl("/WEB-INF", "common", "iframe_upload"); } catch (Exception e) { log.error("文件上传发生错误", e); model.addAttribute("error", e.getMessage()); } return FrontUtils.getTplPathUrl("/WEB-INF", "common", "iframe_upload"); } private static final Logger log = LoggerFactory.getLogger(DoctorAct.class); private static final String RESULT_PAGE = "/WEB-INF/common/iframe_upload"; @Autowired protected FileRepository fileRepository; @Autowired private IMsSystemConfigService scService;