zoukankan      html  css  js  c++  java
  • 异步提交图片

    简单总结一下uploadify提交图片方法

    js代码:

         $("#headPicture").uploadify({
                    height: 32,
                     132,
                    swf: '/js/uploadify/uploadify.swf',
                    uploader: '/user/UpLoadPicture',
                    buttonText: '上传头像',          
                    formData:{
                        //action:'uploadImg'
                    },
                    successTimeout: 99999,
                    fileSizeLimit: '2MB',
                    fileTypeExts:'*.jpg;*.jpge;*.png',                  
                    onUploadSuccess: function (file,data,response) {
                        var result = JSON.parse(data);
                        if (result.Result) {                      
                            $("#headPic").attr("src","data:image/"+result.Data.split('|')[0]+";base64,"+result.Data.split('|')[1]);
                        }
                    }
                });


    html代码:

     <img src="/img/Exchange.png" class="EX_Gold_img fl" id="headPic">
     <input id="headPicture" class="hidden" type="file" name="headPicture" value="">

    后台c#代码:

            [HttpPost]
            public ActionResult UpLoadPicture( )
            {
               
                ReturnResult result = new ReturnResult() { Result = true };
    
                if (this.Request.Files.Count > 0)
                {
                    var file = this.Request.Files[0];
                    List<String> lastNameAlow = new List<String>() { "gif", "jpeg", "png", "jpg" };
                    String lastName = file.FileName.Split('.')[file.FileName.Split('.').Length - 1];
                    if (lastNameAlow.Exists(a => a == lastName.Trim().ToLower()))
                    {
                        byte[] bytes = new byte[file.InputStream.Length];
                        file.InputStream.Read(bytes, 0, bytes.Length);
                        String s = Convert.ToBase64String(bytes);
                        result.Result = true;
                        result.Data = lastName + "|" + s;
                    }
                }
                return this.Json(result);
            }


    另外需要引用外部css文件、js文件、以及上传用的swf文件

       <link href="/js/uploadify/uploadify.css" rel="stylesheet" />
       <script src="/js/uploadify/jquery.uploadify.js"></script>

    swf文件不用动

    uploadify文件下载链接:  http://files.cnblogs.com/files/xbblogs/uploadify.zip

  • 相关阅读:
    用SSMS连接Azure Sql Database 与连接本地库的一些操作区别
    python_高级进阶(3)线程
    python_高级进阶(2)进程与并发
    python_高级进阶(1)进程与并发
    python网络(2)_Udp协议
    python网络(2)_Tcp协议
    python网络(1)_认知
    python异常处理
    python面向对象(5)__特殊双下方法
    python面向对象(4)_细分类的组成成员
  • 原文地址:https://www.cnblogs.com/xbblogs/p/4787674.html
Copyright © 2011-2022 走看看