jquery.uploadify 使用過程

來源:互聯網
上載者:User

HTML:

    swfupload_ajax_demo            <script src="../js/jquery-1.7.2.min.js" type="text/javascript"></script>        <script type="text/javascript" src="../js/jquery.uploadify-v2.1.0/swfobject.js"></script>    <script type="text/javascript" src="../js/jquery.uploadify-v2.1.0/jquery.uploadify.v2.1.0.min.js"></script>    <script type="text/javascript">        var swfu;        $(document).ready(function () {                      $("#uploadify").uploadify({                'height': 30,                'onSelect': function (e, queueId, fileObj) {                    fileObj.name = "mylovemercedes";                    alert("唯一標識:" + queueId + "\r\n" +                  "檔案名稱:" + fileObj.name + "\r\n" +                  "檔案大小:" + fileObj.size + "\r\n" +                  "建立時間:" + fileObj.creationDate + "\r\n" +                  "最後修改時間:" + fileObj.modificationDate + "\r\n" +                  "檔案類型:" + fileObj.type                 );                },                'uploader': '../js/jquery.uploadify-v2.1.0/uploadify.swf',                'script': '../Handler/UploadHandler.ashx',                'scriptData': { 'student_id': $('#hidStudentID').val() },  //自訂傳遞參數                 'method': 'GET',                'cancelImg': '../js/jquery.uploadify-v2.1.0/cancel.png',                'folder': '../upload/student_head',                'queueID': 'fileQueue',                'auto': false,                'multi': false,                'width': 120,                'fileExt': '*.jpg;*.png;*.gif',                'buttonText': "upload image",                'onInit': function () { alert("1"); },                'sizeLimit': 102400, //上傳檔案的大小限制,單位為位元組 100k                 'onAllComplete': function (event, data) { //當上傳隊列中的所有檔案都完成上傳時觸發                     alert(data.filesUploaded + ' 個檔案上傳成功!');                }            });            function uploadpara() {                //自訂傳遞參數                 $('#uploadify').uploadifySettings('scriptData', { 'student_id': $('#hidStudentID').val() });                $('#uploadify').uploadifyUpload();            }        });      </script>    

.UploadHandler.ashx

public class UploadHandler : IHttpHandler    {        public void ProcessRequest(HttpContext context)        {            context.Response.ContentType = "text/plain";            context.Response.Charset = "utf-8";            string student_id = CommonClass.Request.GetRequest("student_id", "");            HttpPostedFile file = context.Request.Files["Filedata"];            string uploadPath =                HttpContext.Current.Server.MapPath(@context.Request["folder"]) + "\\";            if (file != null)            {                if (!Directory.Exists(uploadPath))                {                    Directory.CreateDirectory(uploadPath);                }                file.SaveAs(uploadPath + file.FileName);                //下面這句代碼缺少的話,上傳成功後上傳隊列的顯示不會自動消失                context.Response.Write("1");            }            else            {                context.Response.Write("0");            }        }        public bool IsReusable        {            get            {                return false;            }        }    }


聯繫我們

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