簡單實現限制uploadify上傳個數_jquery

來源:互聯網
上載者:User

簡單實現限制uploadify上傳個數

function deleteUrl(){   $("body").on("click",".img-wrap .mask span",function(event){    event.stopPropagation();              var qs=$('#file_upload-queue>div');//所有的隊列    var id=qs.eq(2).attr('id');//得到第三個隊列的id    $('#uploadTowedAccredit').uploadify('cancel',id);//這樣就行了,會自動重設隊列數量和刪除dom對象,不能直接qs.eq(2).remove(),無效          /*    if(!window.confirm("您確定刪除附件?")){      return;    }    var imgUrl=$(this).parents(".img-wrap").find("img").attr("src");    deleteImage(imgUrl);    $(this).parents(".img-wrap").remove();    */  });};
<li class="blockli clearfix" style="padding-bottom: 5px;">  <span class="left-name"><em class="red-star">*</em>拖機授權委託書:</span>  <div class="upload-wrap" style="width:100px;">    <input type="file" name="uploadTowedAccredit" id="uploadTowedAccredit" class="filetext"/>  </div>  <span id="uploadTowedAccreditLinkTip" class="warn-tips"><em></em>請上傳附件,最多上傳${towedAccreditPicMax} 張</span>  <div id="towedAccreditDiv" class="up-img-list clearfix"></div></li>
// 上傳拖機授權委託書function uploadTowedAccreditInit(){   $("#uploadTowedAccredit").uploadify({    'hideButton':'true',    'preventCaching' : 'true',    'checkExisting':'true',    'swf': SWF,     'uploader':uploadImg,    'debug':false,    'multi': true,    'method': 'post',    'preventCaching' : true,    'removeCompleted' : true,    'removeTimeout' : 10,    'requeueErrors' : true,    'successTimeout' : 30,    'uploadLimit' : ${towedAccreditPicMax},         'fileObjName' : 'Filedata',    //單張圖片最大限制    'fileSizeLimit' : '1024KB',    'fileTypeDesc' : 'Image Files',    //僅限上傳jpg格式圖片    'fileTypeExts' : '*.jpg;*.png',    'height': 24,    'width':73,    'buttonText' : '上傳附件',    'auto': true,    'buttonClass':'uploada btn-fff-24',       'onSWFReady' : function() {    },         'onInit':function(){      // $("#file_upload-button").css("width","100");     },             //選擇圖片完成    'onSelect' : function() {     },         //取消上傳    'onCancel' : function(file) {    },    'onCheck': function(event,data,key) {    },    //開始上傳    'onUploadStart' : function(file) {      $('.uploadify-queue').html('');    },         //上傳過程中    'onUploadProgress' : function(file, bytesUploaded, bytesTotal, totalBytesUploaded, totalBytesTotal) {      $('.uploadify-queue').html('');      $("#uploadTowedAccreditLinkTip").html('<em></em>上傳中...');    },         //上傳完成    'onUploadComplete' : function(file) {        $('.uploadify-queue').html('');        $("#uploadTowedAccreditLinkTip").html('<em></em>上傳成功,待提交');    },         //上傳成功    'onUploadSuccess' : function(file, data, response) {      var obj = eval('(' + data + ')');        var result=obj.result;        if(result=="true"){          var filename=obj.filename;          $('.uploadify-queue').html('');          $('#towedAccreditDiv').append("<div class='img-wrap'><img width='112' height='84' alt='' src='"+filename+"'><div class='mask'><em></em><span></span></div></div>");        }    },         //上傳失敗 //附件格式不正確,請上傳JPG、BMP、PNG格式檔案,大小不超過3MB    'onUploadError' : function(file, errorCode, errorMsg, errorString) {      switch(errorCode) {        case -100:          alert("上傳的檔案數量已經超出系統限制的"+$('#uploadTowedAccredit').uploadify('settings','queueSizeLimit')+"個檔案!");          break;        case -110:          alert("檔案 ["+file.name+"] 大小超出系統限制的"+$('#uploadTowedAccredit').uploadify('settings','fileSizeLimit')+"大小!");          break;        case -120:          alert("檔案 ["+file.name+"] 大小異常!");          break;        case -130:          alert("檔案 ["+file.name+"] 類型不正確!");          break;      }    },    //上傳失敗 //附件格式不正確,請上傳JPG、BMP、PNG格式檔案,大小不超過3MB    'onSelectError' : function(file, errorCode, errorMsg) {       var msgText = "上傳失敗\n";       switch (errorCode) {         case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:           var towedAccreditDivLen = $("#towedAccreditDiv").children().length;          msgText += "每次最多上傳 " + $('#uploadTowedAccredit').uploadify('settings','uploadLimit') + "個檔案";           break;         case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:           msgText += "檔案大小超過限制( " + $('#uploadTowedAccredit').uploadify('settings','fileSizeLimit') + " )";           break;         case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:           msgText += "檔案大小為0";           break;         case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:           msgText += "檔案格式不正確,僅限 " + $('#uploadTowedAccredit').uploadify('settings','fileTypeExts');           break;         default:           msgText += "錯誤碼:" + errorCode + "\n" + errorMsg;       }      alert(msgText);    }  });     //判斷使用者是否有安裝flash var obj = $("#uploadTowedAccredit").children().eq(0); if(obj.attr('type')!= "application/x-shockwave-flash"){    alert('系統檢測到您的瀏覽器沒有安裝flash外掛程式,為了你能夠正常上傳圖片,建議你安裝flash');    return;  }     $("#uploadTowedAccredit").css("float","left");};

另外給大家附上jquery+uploadify多檔案上傳

<html xmlns=”http://www.w3.org/1999/xhtml”><head><meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ /><title>php jquery uploadify多檔案上傳</title><link href=”css/default.css” rel=”stylesheet” type=”text/css” /><link href=”css/uploadify.css” rel=”stylesheet” type=”text/css” /><script type=”text/javascript” src=”js/jquery-1.3.2.min.js”></script><script type=”text/javascript” src=”js/swfobject.js”></script><script type=”text/javascript” src=”js/jquery.uploadify.v2.1.0.min.js”></script><script type=”text/javascript”>$(document).ready(function() {$(“#fileInput2″).uploadify({‘uploader': ‘js/uploadify.swf',//所需要的flash檔案‘cancelImg': ‘cancel.png',//單個取消上傳的圖片'script': ‘js/uploadify.php',//實現上傳的程式‘folder': ‘uploads',//服務端的上傳目錄//'auto': true,//自動上傳‘multi': true,//是否多檔案上傳//'checkScript': ‘js/check.php',//驗證 ,服務端的‘displayData': 'speed',//進度條的顯示方式//'fileDesc': ‘Image(*.jpg;*.gif;*.png)',//對話方塊的檔案類型描述//'fileExt': ‘*.jpg;*.jpeg;*.gif;*.png',//可上傳的檔案類型//'sizeLimit': 999999 ,//限制上傳檔案的大小//'simUploadLimit' :3, //並發上傳資料//'queueSizeLimit' :5, //可上傳的檔案個數//'buttonText' :'檔案上傳',//通過文字替換鈕扣上的文字‘buttonImg': ‘css/images/browseBtn.png',//替換上傳鈕扣‘width': 80,//buttonImg的大小‘height': 24,//‘rollover': true,//button是否變換onComplete: function (evt, queueID, fileObj, response, data) {//alert(“Successfully uploaded: “+fileObj.filePath);//alert(response);getResult(response);//獲得上傳的檔案路徑}//onError: function(errorObj) {// alert(errorObj.info+” “+errorObj.type);//}});});</script><script type=”text/javascript”>function getResult(content){//通過上傳的圖片來動態產生text來儲存路徑var board = document.getElementById(“divTxt”);board.style.display=””;var newInput = document.createElement(“input”);newInput.type = “text”;newInput.size = “45″;newInput.name=”myFilePath[]“;var obj = board.appendChild(newInput);var br= document.createElement(“br”);board.appendChild(br);obj.value=content;}</script></head><body><fieldset style=”border: 1px solid #CDCDCD; padding: 8px; padding-bottom:0px; margin: 8px 0″><legend> <strong> 多檔案上傳</strong></legend><div><input id=”fileInput2″ name=”fileInput2″ type=”file” /><input type=”button” value=”確定上傳” onclick=”javascript:$(‘#fileInput2′).uploadifyUpload();”>  ||  <a href=”javascript:$(‘#fileInput2′).uploadifyClearQueue();”>清除上傳列表</a></div><p></p></fieldset><FORM name=”form2″ METHOD=POST ACTION=”db.php”> <div id=”divTxt” style=”display:none”><span style=”color:red”><strong>已經上傳的圖片有:</strong></span& gt;<br></div><br><INPUT TYPE=”submit” value=”提 交”></FORM></body></html>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.