标签:
<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; }
标签:
原文地址:http://www.cnblogs.com/luoxiaolei/p/5210664.html