IE9文件上传

<form id="imgUploadForm" class="form-horizontal js-form col-md-10">
    <label class="col-md-2 control-label">附件:</label>
    <div class="input-group col-md-10">
        <!--<input class="form-control" readonly="readonly" name="FILE_PATH"/>-->
        <input id="js-input-file" name="filename" class="js-fileupload" accept="image/*" type="file" multiple/>
    </div>
</form>
1、form 提交
<iframe name="ifr" id="ifr" style="height: 0;width: 0"></iframe>

var fileObj = that.$("#js-input-file");
var fileName = fileObj.val();
if (fileName == "") {
    ngc.info('请先选择文件');
    return;
}
ngc.progress("上传中");
var url = ngc.getContext() + "/fileUpload.spj?method=picStoreUpload&resTypeId=" + that.options.resTypeId + "&resId=" + that.options.resId + "&len=1";
var form = that.$("#imgUploadForm");
form.attr("method", "post");
form.attr("enctype", "multipart/form-data");
form.attr("target", "ifr");
form.attr("action", url);
form.submit();
$("#ifr").load(function () {
    clearTimeout(that.options.time);
    that.options.time = setTimeout(function(){
        var result = $($("#ifr")[0].contentWindow.document.body).text();
        ngc.progress();
        if (result.indexOf("fail") > -1) {
            ngc.info("上传失败");
        } else {
            ngc.info("上传成功");
            that.queryImg();
        }
        $("#imgUploadForm")[0].reset();
    },500)
})
2、jquery-form插件提交  https://github.com/jquery-form/form

if(!$("#js-input-file")[0].value) {
    ngc.info("请选择至少一个文件");
    return;
}
ngc.progress("上传中");
var url =ngc.getContext() + "/fileUpload.spj?method=picStoreUpload&resTypeId="+this.options.resTypeId+"&resId="+this.options.resId+"&len=1";
var options = {
    url : url,
    type: 'POST',
    success : function(data){
        ngc.progress();
        ngc.info("上传成功");
        that.queryImg();
    },
    error : function(){
        ngc.progress();
        ngc.info("上传失败");
        $("#imgUploadForm")[0].reset();
    },
    resetForm : true
};
$("#imgUploadForm").ajaxSubmit(options);

后台
public void picStoreUpload(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    response.setContentType("text/html;charset=UTF-8");
    response.setCharacterEncoding("utf-8");
    PrintWriter out = response.getWriter();
    List<String> picIds = new ArrayList<String>();
    MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
    String resTypeId = request.getParameter("resTypeId") == null ? "0" : request.getParameter("resTypeId");
    String resId = request.getParameter("resId") == null ? "0" : request.getParameter("resId");
    int len = Integer.parseInt(request.getParameter("resId") == null ? "0" : request.getParameter("len"));
    List<MultipartFile> imgFile = multipartRequest.getFiles("filename");
    for(MultipartFile multipartFile:imgFile){
        String picId = propertyDataBizService.savePhotoAndVideo(resTypeId, resId, 0, (CommonsMultipartFile)multipartFile);
        picIds.add(picId);
    }
    out.write(picIds.toString());
    out.flush();
    out.close();
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值