首页 > 代码库 > jquery的ajaxFileUpload异步上传

jquery的ajaxFileUpload异步上传

 js代码
1
function ajaxFileUpload() { 2 var loading=‘<li class="close loading" ><img id="loading" src="http://www.mamicode.com/{weiwin::$staticFilePath}/style/img/nopic.png"/></li>‘; 3 $(‘#aaa‘).append(loading); 4 $(‘#loading‘).bind("click",function(){ 5 $(‘#openwinbg01‘).css("display","block"); 6 $(‘#openwin01‘).css("display","block"); 7 }); 8 $.ajaxFileUpload 9 (10 {11 url: "./index.php?g=Wap&m=Junk&a=upload", //用于文件上传的服务器端请求地址12 secureuri: false, //一般设置为false13 fileElementId: ‘file1‘, //文件上传空间的id属性 <input type="file" id="file" name="file" />14 dataType: ‘json‘, //返回值类型 一般设置为json15 success: function (data) //服务器成功响应处理函数16 {17 $(‘.loading‘).remove();18 //alert(111);19 // var img=$(‘#imgio‘).val();20 var dlid=$(‘#io‘).val()*1;21 //var img="<dl><img src=http://www.mamicode.com/‘"+data+"‘ id=‘"+id+"‘/><button class=‘close‘>删</button></dl>";22 var img=‘<li data-role="img" class="close clo" id="‘+dlid+‘"><img src="http://www.mamicode.com/‘+data+‘" class="img11"></li>‘;23 $("#aaa").append(img);24 var io=$(‘#io‘).val()*1+1;25 $("#io").attr(‘value‘,io);26 27 },28 error: function (data, status, e)//服务器响应失败处理函数29 {30 alert(e);31 },32 complete :function(){33 34 $(‘.clo‘).bind("click",function(){35 $(‘#openwinbg‘).css("display","block");36 $(‘#openwin‘).css("display","block");37 var ii = $(this).attr(‘id‘)*1+1;38 //alert(ii);39 $(‘#ii‘).attr(‘value‘,ii);40 });41 }42 }43 )44 return false;45 }
html代码
 1 <input type="file" capture="camera" class="input-file" name="file1" id="file1" onchange="ajaxFileUpload()" /> 
thinkphp后天代码
 1  //文件上传 2         public  function upload(){ 3                 import("@.ORG.UploadFile"); 4                 $upload = new UploadFile();// 实例化上传类 5                 $upload->maxSize  = 31457280000;// 设置附件上传大小 6                 //$upload->allowExts  = array(‘jpg‘, ‘gif‘, ‘png‘, ‘jpeg‘);// 设置附件上传类型 7                 $upload->savePath =  ‘./Uploads/file/‘.date(‘ymd‘).‘/‘;// 设置附件上传目录 8                 $upload->imageClassPath     = ‘@.ORG.Image‘; 9                 //设置需要生成缩略图,仅对图像文件有效10                 $upload->thumb = true;11                 //设置需要生成缩略图的文件后缀12                 $upload->thumbPrefix = ‘m_‘;  //生产2张缩略图13                 //设置缩略图最大宽度14                 $upload->thumbMaxWidth = ‘480‘;15                 //设置缩略图最大高度16                 $upload->thumbMaxHeight = ‘320‘;17                 if(!$upload->upload()) {// 上传错误提示错误信息18                     echo 0;19                 }else{20                 $info=$upload->getUploadFileInfo();21                 echo $upload->savePath.‘m_‘.$info[0][‘savename‘];22                 }23         }

 

 

jquery的ajaxFileUpload异步上传