asp. net + uploadify 이미지 업로드 실현

4974 단어 uploadify
전단 코드 는 다음 과 같다.
$("#file_upload").uploadify({

        'auto': true,

        'swf': '/template/js/cutImg/uploadify/uploadify.swf',

        'uploader': '/template/js/cutImg/upload.ashx',

        'multi': false, //         

        'queueID': 'fileQueue', //           id,       div   

        'cancelImage': '/template/js/cutImg/uploadify/uploadify-cancel.png', //[    ]       

        'buttonText': '', //       

        'buttonImage': '/template/images/people.png', //         

        'width': 100, //        

        'height': 30,

        'removeCompleted': true,  //                    。   True,                  

        "removeTimeout": "0", //                  ,   3

        "fileSizeLimit": "4096KB", //        ,     KB

        "fileTypeExts": "*.jpg;*.gif;*.png", //           。  *.*

        "formData": { "folder_name": "UserHead" },

        "onSelect": function () { //       

            //  Uploadify

            //$("#file_upload").uploadify("disable", true);

        },

        'overrideEvents': ['onSelectError', 'onDialogClose'], //        

        'onFallback': function () { //  FLASH    

            FunMsg("    FLASH  ,    !   FLASH     。");

        },

        "onSelectError": function (file, errorCode, errorMsg) {

            //         ,  file,erroCode,errorMsg    

           

          

            var settings = this.settings;

            if (errorCode == -110) {

                FunMsg("      " + settings.fileSizeLimit);

            }

            if (errorCode == -130) {

                FunMsg("       :*.jpg;*.gif;*.png");

            }

        },

        "onUploadStart": function (file) {

           



            //        

            //$("#file_upload").uploadify("settings", "formData", {"id":"1"});

        },

        "onUploadError": function (file, errorCode, erorMsg, errorString) {

           

        },

        "onUploadSuccess": function (file, data, response) {

                    //      ,data              

         }

   });


 배경 코드 는 다음 과 같 습 니 다.
        public void ProcessRequest(HttpContext context)

        {

            context.Response.ContentType = "text/plain";

            context.Response.Charset = "utf-8";



            HttpPostedFile file = context.Request.Files["Filedata"];          



            if (file != null)

            {

                //        

                string fileExtension = Path.GetExtension(file.FileName);//       

                //      

                if (!CheckValidExt(fileExtension))

                {

                    context.Response.Write("    :       !" + fileExtension);

                    return;

                }

                //    +        

                string strDateTime = DateTime.Now.ToString("yyMMddhhmmssfff");//       

                Random ran = new Random();

                string strRan = Convert.ToString(ran.Next(100, 999));//       

                string saveName = strDateTime + strRan + fileExtension;



                string path = "/UploadFile/";

                string uploadPath = HttpContext.Current.Server.MapPath(path);

                //         ,     

                if (!Directory.Exists(uploadPath))

                {

                    Directory.CreateDirectory(uploadPath);

                }

                file.SaveAs(uploadPath + saveName);

                //          ,                 ,           

                context.Response.Write(path+saveName);

            }

            else

            {

                context.Response.Write("0");

            } 

        }





        ///

        ///           +bool CheckValidExt(string sExt)

        ///

        ///       

        ///        ,  true,    false.

        public bool CheckValidExt(string strExt)

        {

            string AllowExt = "7z|aiff|asf|avi|bmp|csv|doc|docx|fla|flv|gif|gz|gzip|jpeg|jpg|mid|mov|mp3|mp4|mpc|mpeg|mpg|ods|odt|pdf|png|ppt|pptx|pxd|qt|ram|rar|rm|rmi|rmvb|rtf|sdc|sitd|swf|sxc|sxw|tar|tgz|tif|tiff|txt|vsd|wav|wma|wmv|xls|xlsx|xml|zip";//       

            bool flag = false;

            string[] arrExt = AllowExt.Split('|');

            foreach (string filetype in arrExt)

            {

                if (filetype.ToLower() == strExt.ToLower().Replace(".", ""))

                {

                    flag = true;

                    break;

                }

            }

            return flag;

        }


좋은 웹페이지 즐겨찾기