jQuery上傳外掛程式Uploadify 3.2使用

來源:互聯網
上載者:User

標籤:

Uploadify:http://www.uploadify.com/download/ 這裡下載最新版的3.2的。
下載下來解壓後估計裡面很多檔案,其實有用的也就一個jquery.uploadify.js和uploadify.swf這兩個檔案。當然啦,jQuery庫那是必須的。
在你使用的項目中,把jquery.uploadify.js引入以後,用法和大多數JQ外掛程式一樣。同時也要記得引入swfobject.js這個外掛程式,版本2.2以上的。使用方法例如:

$(function() {

    $("#file_upload_1").uploadify({        height        : 30,        swf           : ‘/uploadify/uploadify.swf‘,        uploader      : ‘/uploadify/uploadify.php‘,        width         : 120    });});

file_upload_1其實也就是一個容器ID,比如上面的只是簡單的案例,下面我就把我在項目中做的發出來,每個都有解釋:

$(document).ready(function() {    $("#file_upload").uploadify({        //開啟調試        ‘debug‘ : false,        //是否自動上傳        ‘auto‘:false,        //逾時時間        ‘successTimeout‘:99999,        //附帶值        ‘formData‘:{            ‘userid‘:‘使用者id‘,            ‘username‘:‘使用者名稱‘,            ‘rnd‘:‘加密密文‘        },        //flash        ‘swf‘: "uploadify.swf",        //不執行預設的onSelect事件        ‘overrideEvents‘ : [‘onDialogClose‘],        //檔案選擇後的容器ID        ‘queueID‘:‘uploadfileQueue‘,        //伺服器端指令碼使用的檔案對象的名稱 $_FILES個[‘upload‘]        ‘fileObjName‘:‘upload‘,        //上傳處理常式        ‘uploader‘:‘imageUpload.php‘,        //瀏覽按鈕的背景圖片路徑        ‘buttonImage‘:‘upbutton.gif‘,        //瀏覽按鈕的寬度        ‘width‘:‘100‘,        //瀏覽按鈕的高度        ‘height‘:‘32‘,        //expressInstall.swf檔案的路徑。        ‘expressInstall‘:‘expressInstall.swf‘,        //在瀏覽視窗底部的檔案類型下拉式功能表中顯示的文本        ‘fileTypeDesc‘:‘支援的格式:‘,        //允許上傳的檔案尾碼        ‘fileTypeExts‘:‘*.jpg;*.jpge;*.gif;*.png‘,        //上傳檔案的大小限制        ‘fileSizeLimit‘:‘3MB‘,        //上傳數量        ‘queueSizeLimit‘ : 25,        //每次更新上傳的檔案的進展        ‘onUploadProgress‘ : function(file, bytesUploaded, bytesTotal, totalBytesUploaded, totalBytesTotal) {             //有時候上傳進度什麼想自己個人化控制,可以利用這個方法             //使用方法見官方說明        },        //選擇上傳檔案後調用        ‘onSelect‘ : function(file) {                          },        //返回一個錯誤,選擇檔案的時候觸發        ‘onSelectError‘:function(file, errorCode, errorMsg){            switch(errorCode) {                case -100:注意修改提示資訊應該是用this.queueData.errorMsg =,如果用alert就會有兩個彈框                    //alert("上傳的檔案數量已經超出系統限制的"+$(‘#file_upload‘).uploadify(‘settings‘,‘queueSizeLimit‘)+"個檔案!");                    break;                case -110:                    alert("檔案 ["+file.name+"] 大小超出系統限制的"+$(‘#file_upload‘).uploadify(‘settings‘,‘fileSizeLimit‘)+"大小!");                    break;                case -120:                    alert("檔案 ["+file.name+"] 大小異常!");                    break;                case -130:                    alert("檔案 ["+file.name+"] 類型不正確!");                    break;}             switch(errorCode) {                    case -100:                        this.queueData.errorMsg = "上傳的檔案數量已經超出系統限制的" + $(‘#photofile‘).uploadify(‘settings‘, ‘queueSizeLimit‘) + "個檔案!";                        break;                    case -110:                        this.queueData.errorMsg = "檔案 [" + file.name + "] 大小超出系統限制的" + $(‘#photofile‘).uploadify(‘settings‘, ‘fileSizeLimit‘) + "大小!";                        break;                    case -120:                        this.queueData.errorMsg = "檔案 [" + file.name + "] 大小異常!";                        break;                    case -130:                        this.queueData.errorMsg = "檔案 [" + file.name + "] 類型不正確!";                        break;            }如果上面的提示還是有英文的話可以使用下面的方法switch (errorCode) {                    case -100:                        this.queueData.errorMsg = "上傳的檔案數量已經超出系統限制的" + $(‘#photofile‘).uploadify(‘settings‘, ‘queueSizeLimit‘) + "個檔案!";                        break;                    case -110:                        this.queueData.errorMsg = "檔案 [" + file.name + "] 大小超出系統限制的" + $(‘#photofile‘).uploadify(‘settings‘, ‘fileSizeLimit‘) + "大小!";                        break;                    case -120:                        this.queueData.errorMsg = "檔案 [" + file.name + "] 大小異常!";                        break;                    case -130:                        this.queueData.errorMsg = "檔案 [" + file.name + "] 類型不正確!";                        break;                }        },        //檢測FLASH失敗調用        ‘onFallback‘:function(){            alert("您未安裝FLASH控制項,無法上傳圖片!請安裝FLASH控制項後再試。");        },        //上傳到伺服器,伺服器返回相應資訊到data裡        ‘onUploadSuccess‘:function(file, data, response){            alert(data);        }    });});
js代碼及解釋

 

jQuery上傳外掛程式Uploadify 3.2使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.