前端引入文件



Ajax进度条异步处理


$(function () {
      $("#myupload").ajaxForm({
          dataType:'json',
          beforeSend:function(){ 
                  $(".progress").show();
          },
          uploadProgress:function(event,position,total,percentComplete){
                  var percentVal = percentComplete + '%';
                  $(".progress-bar").width(percentComplete + '%');
                  $(".progress-bar").html(percentVal);
                  $(".sr-only").html(percentComplete + '%');
          },
          success:function(data){
                  $(".progress").hide();
          
                  if(data.error == "empty_name"){
                          alert("文件上传非法,上传失败!");
                          exit();
                  };
                  if(data.error == "large"){
                          alert("图片上传不能大于2M,上传失败!");
                          exit();
                  };
  
  /*alert(data.error);*/
                  if(data.error == "format"){
                          alert("图片格式错误,上传失败");
                          //alert(data.type);
                          exit();
                  };
  
                  //alert("上传成功!");
                  //files.html(""+data.name+"("+data.size+"k) 删除");
                  $(".files").html("文件名: "+data.name+"   del   大小:"+data.size);
                  var img = "http://www.sandleft.com/test/input/upload/files/"+data.pic;
                  $(".showimg").html("");
                  alert("上传成功!");
          },
          error:function(){
                  alert("图片上传失败");
          }
          
      });
      $(".progress").hide();
});

前端上传HTML

 

                
文件上传