uploadify build: 3.2.1
核心代码
html: <tr><td><div id="fileQueue"></div></td></tr>
<tr><td colspan="2">上传证件:<input id="uploadify" type="file" multiple="true"/><p>
<a href="javascript:$('#uploadify').uploadify('upload','*')">开始上传</a>|
<a href="javascript:$('#uploadify').uploadify('cancel','*')">取消上传</a>
</p>支持上传的类型:<span class="bt_n">png、jpg、gif、jpeg。</span></td></tr>
js:$("#uploadify").uploadify({
'method':"post",
'uploader':tool.getRootPath()+"upload/uploadimg.action",
'swf' : tool.getRootPath()+"static/plugins/uploadify/uploadify.swf",
//'checkExisting' :tool.getRootPath()+"upload/uploadimg.action",
//'buttonImage': tool.getRootPath()+"static/plugins/uploadify/uploadify-cancel.png",
'fileSizeLimit' : '1MB',
'fileTypeExts' : '*.gif; *.jpg; *.png; *.jpeg',
'fileTypeDesc' : "支持上传的类型:gif、jpg、png、jpeg",
'queueID': 'fileQueue',
'auto' : false,
'multi' : true,
'simUploadLimit' : 2,
'removeTimeout' : 10,
'buttonText' : '浏览'
});
java action:
public class UploadAction extends BaseAdminAction{
private static Logger logger = Logger.getLogger(UploadAction.class);
private File uploadify;
private String uploadifyFileName;
private String filepath;
/**
* 上传图片
* @return 图片路径
*/
@Action(value="uploadimg",results={@Result(name="uploadimg",type="json",params={"root","filepath"})})
public String uploadimg(){
String savePath = ServletActionContext.getServletContext().getRealPath("/UploadFile");//上传完后文件存放位置
System.out.println(savePath);
String newsuffix = "";
String current=new java.text.SimpleDateFormat("yyyyMMdd").format(new Date());
if((uploadifyFileName != null)&&(uploadifyFileName.length()>0))
{
int dot = uploadifyFileName.lastIndexOf(".");
if((dot >-1) && (dot < (uploadifyFileName.length() - 1)))
{
newsuffix = uploadifyFileName.substring(dot + 1);
}
}
try {
FileInputStream fis = new FileInputStream(uploadify);
filepath = savePath+"/"+current + "." + newsuffix;
FileOutputStream fos = new FileOutputStream(filepath);
IOUtils.copy(fis, fos);
fos.flush();
fos.close();
fis.close();
} catch (Exception e) {
logger.error("图片上传错误", e);
filepath="";
}
return "uploadimg";
}
在进入uploadimg方法时 uploadify,uploadifyFileName为NULL 求小伙伴们指点