<div class="photo" style="display:none;" id="upPhoto"><div class="pop-cover"></div><div style="position: absolute; top:30%; left:5%; width:90%; margin:0 auto; z-index:99;">
<a href="#" class="potos tbtm" ><input type="file" name="file" id="file1"  style="display:block; width:100%; text-align:center; opacity: 0;  cursor:pointer;"/><span style=" z-index:1; position:relative; top:-8px; ">本地上传</span></a><a href="#" class="cancel">取消</a></div></div>  
    </div>
  </section>
   </div>
    </form>
</body>
<script type="text/javascript" src="js/lib/jquery-1.9.0.min.js"></script>
<script type="text/javascript" src="js/lib/ajaxfileupload.js"></script>
<script>

$(document).ready (function () {

$("#head").click(function () {
        $(".photo").show();

});
    $("#file1").on("change", function () {
        change();
    })
    function change(target) {
        $(".photo").hide();
        var allowExtention = ".jpg,.bmp,.png,.jpeg";
       // console.log(target);
        var input = document.getElementById("file1"); //获取input标签
        var extention = input.value.substring(input.value.lastIndexOf(".") + 1).toLowerCase(); //截取后缀
        if (extention && allowExtention.indexOf(extention) > -1) {  //判断上传图片类型
            var fileSize = input.files[0].size; //获取上传图片大小
            if (fileSize) {
                if (fileSize <1.5* 1000 * 1024) {  //js限制图片上传大小
                    ajaxFileUpload();
                }
                else
                    addSystemTip($page, "上传图片过大!");
            }

}
        else
            addSystemTip($page, "上传图片格式不正确!");

}

// 使用jquery ajaxFileupload插件 原理是把一个form提交到后端来获取图片

//所以 input type=file 标签必须要给一个 name属性,是必须的否则后台无法获取图片
    function ajaxFileUpload() {
        $.ajaxFileUpload({
            url: "MyAccount.aspx?type=img"////用于文件上传的服务器端请求地址
            , secureuri: false // //是否需要安全协议,一般设置为false
            , fileElementId: 'file1' //文件上传域的ID
            , dataType: 'json' //返回值类型 一般设置为json
          //  , type: 'post'
            , success: function (data, status)  //服务器成功响应处理函数
            {                             
                $("#img").attr("src", data.imgurl);
                //  var input = document.getElementById("file1");
                var span = $("#file1").next();
                $("#file1").remove();   //上传成功后删除file标签,否则无法继续上传          
                var ele = $('<input type="file" name="file"  id="file1" style="display:block; width:100%; text-align:center; opacity: 0;  cursor:pointer;"/>'); //重新创建file标签
                ele.insertBefore(span);
                ele.on("change", function () { //重新绑定change事件句柄
                    change();
                })            
                $(".photo").hide();
            },
            error: function (data, status, e)//服务器响应失败处理函数
            {
                $(".photo").hide();
            }
        });        
    }
    $(".cancel").click(function () {

$(".photo").hide();

})
    $(".pop-cover").mousemove(function () {

$(".photo").hide();

})
})
</script>
</html>

//对应后台代码,并且将上传图片重新绘画一下 指定像素大小

public partial class MyAccount : MemberBase
    {
        public MemberDetails user = new MemberDetails();
        
        public string ImageURl = "";
        public string encodeName = "";
        public string sex = "保密";
        string domain = XpVShop.MyFuc.Utils.GetAppSettingValue("turnUrl") + "/Upload/users/";
        string localUrl = XpVShop.MyFuc.Utils.GetAppSettingValue("PCUploadPath2");

// string domain = "http://localhost:89/Upload/images/";//本地测试使用
       // string localUrl=@"F:\hz\code\aishop\Publish\vshop\Upload\images\";
      
        protected void Page_Load(object sender, EventArgs e)
        {

if (!IsPostBack)
            {
                XpVShop.MyFuc.LogHelper.Write("MyAccount mid:" + CurrentUser.MemberID);
                user = MemberBLL.GetMemberDetails(CurrentUser.MemberID);
                string u = "vshop_ChangeName.aspx";
                encodeName = XpVShop.MyFuc.Utils.UrlEncode(u);
                if (user.Photo.IndexOf("http://wx.qlogo.cn") == -1)
                    ImageURl = domain + user.Photo;
                else
                    ImageURl = user.Photo;
                if (!string.IsNullOrEmpty(user.Mobile))
                    user.Mobile = user.Mobile.Substring(0, 5) + "***" + user.Mobile.Substring(user.Mobile.Length - 1, 1);
                ;
                if (user.Sex) sex = "男";
                else sex = "女";
                string type = Utils.ReqStrParams("type", "");
                if (type == "img")
                {
                    HttpFileCollection files = Request.Files;
                    string msg = string.Empty;
                    string error = string.Empty;
                    string imgurl;

if (files.Count > 0)
                    {
                        string name = System.IO.Path.GetFileName(files[0].FileName);
                        // string url = Server.MapPath("Upload/images/") + CurrentUser.MemberID + name;

XpVShop.MyFuc.LogHelper.Write(" MyAccount 存放路径 localUrl:" + localUrl);
                        try
                        {
                            string strGuid = System.Guid.NewGuid().ToString().ToUpper(); //始化 Guid 类的新
                            string strFileExt = name.Substring(name.LastIndexOf(".")); //得到图片的后缀
                            string path = localUrl + strGuid  + strFileExt;
                            System.Web.HttpPostedFile postedFile = files[0];
                            XpVShop.MyFuc.LogHelper.Write("MyAccount 存放地址之前;" + path);                        
                           // files[0].SaveAs(localUrl + CurrentUser.MemberID + name);
                            XpVShop.MyFuc.Utils.GetThumbNail(name, 350,200, "image/pjpeg", false, postedFile.InputStream, path);
                            imgurl = strGuid + strFileExt;
                            user.Photo = imgurl;                        
                            MemberBLL.UpdateMemberPhoto(user);
                            CurrentUser.Photo = imgurl;
                            ImageURl = domain + user.Photo;
                            XpVShop.MyFuc.LogHelper.Write(" MyAccount 保存图片路径" + ImageURl + "保存数据库字段:user.Photo:" + imgurl + "存放地址 " + path);
                            // msg = " 成功! 文件大小为:" + files[0].ContentLength;                                              
                            string res = "{ error:'" + error + "', msg:'" + msg + "',imgurl:'" + ImageURl + "'}";
                            Response.Write(res);
                            Response.End();
                        }
                        catch (Exception ex)
                        {
                            XpVShop.MyFuc.LogHelper.Write("MyAccount ex:" + ex.ToString());

}

}
                }
            }

}     
    }

/// <summary>
           /// 处理上传图片为指定像素
           /// </summary>
           /// <param name="strFileName">文件名</param>
           /// <param name="iWidth"></param>
           /// <param name="iheight"></param>
           /// <param name="strContentType">图片类型</param>
           /// <param name="blnGetFromFile">是否是从本地文件名获取文件流</param>
           /// <param name="ImgStream">文件流</param>
           ///  <param name="path">保存路径</param>
           public static void GetThumbNail(string strFileName, int iWidth, int iheight, string strContentType, bool blnGetFromFile, System.IO.Stream ImgStream, string path)
           {
               System.Drawing.Image oImg;
               if (blnGetFromFile) oImg = System.Drawing.Image.FromFile(strFileName);
               oImg = System.Drawing.Image.FromStream(ImgStream);
               oImg = oImg.GetThumbnailImage(iWidth, iheight, null, IntPtr.Zero);   //GetThumbnailImage方法是返回此Image对象的缩略图
              // string strGuid = System.Guid.NewGuid().ToString().ToUpper(); //始化 Guid 类的新
              // string strFileExt = strFileName.Substring(strFileName.LastIndexOf("."));  //得到图片的后缀
               //MemoryStream MemStream = new MemoryStream(); //创建其支持存储区为内存的流     
               oImg.Save(path);             
           }

html5 完整图片上传的更多相关文章

  1. MVC4中基于bootstrap和HTML5的图片上传Jquery自定义控件

    场景:mvc4中上传图片,批量上传,上传前浏览,操作.图片进度条. 解决:自定义jquery控件 没有解决:非图片上传时,会有浏览样式的问题; 解决方案; 1.样式 – bootstrap 的css和 ...

  2. iOS 开发之路(WKWebView内嵌HTML5之图片上传) 五

    HTML5页面的图片上传功能在iOS端的实现. 首先,页面上用的是plupload组件,在wkwebview上存在两个坑需要修复才能正常使用. 问题:在webview上点击选择照片/相机拍摄,就会出现 ...

  3. hybird app项目实例:安卓webview中HTML5拍照图片上传

    应用的平台环境:安卓webview: 涉及的技术点: (1) <input type="file" > :在开发中,安卓webview默认点击无法调用文件选择与相机拍照 ...

  4. 【转】HTML5 jQuery图片上传前预览

    hTML5实现表单内的上传文件框,上传前预览图片,针刷新预览images,本例子主要是使用HTML5 的File API,建立一個可存取到该 file的url,一个空的img标签,ID为img0,把选 ...

  5. HTML5 jQuery图片上传前预览

    hTML5实现表单内的上传文件框,上传前预览图片,针刷新预览images,本例子主要是使用HTML5 的File API,建立一個可存取到该file的url,一个空的img标签,ID为img0,把选择 ...

  6. HTML5 之图片上传预处理

    在开发 H5 应用的时候碰到一个问题,应用只需要一张小的缩略图,而用户用手机上传的确是一张大图,手机摄像机拍的图片好几 M,这可要浪费很多流量. 像我这么为用户着想的程序员,绝对不会让这种事情发生的, ...

  7. html图片上传阅览并且点击放大

                  关闭   qq_31540195的博客       目录视图 摘要视图 订阅 异步赠书:9月重磅新书升级,本本经典           程序员9月书讯      每周荐书: ...

  8. HTML5笔记:跨域通讯、多线程、本地存储和多图片上传技术

    最近做项目在前端我使用了很多新技术,这些技术有bootstrap.angularjs,不过最让我兴奋的还是使用了HTML5的技术,今天我想总结一些HTML5的技术,好记性不如烂笔头,写写文章可以很好的 ...

  9. LocalResizeIMG前端HTML5本地压缩图片上传,兼容移动设备IOS,android

    LocalResizeIMG前端HTML5本地压缩图片上传,兼容移动设备IOS,android jincon 发表于 2015-02-26 18:31:01 发表在: php开发 localresiz ...

随机推荐

  1. pascal闪电入门系列目录

    第一章  准备工作 第二章  Hello,world! 第三章  输出.输入 第四章  变量常量.基本数据类型 第五章  格式.注释 第六章  运算符.表达式.优先级 第七章  分支结构 第八章  数 ...

  2. Java入门记(四):容器关系的梳理(上)——Collection

    目录 一.Collection及子类/接口容器继承关系 二.List 2.1 ArrayList 2.1.1 序列化的探讨 2.1.2 删除元素 2.1.3 调整大小 2.2 Vector和Stack ...

  3. vim中 set 用法设置

    vi set用法from google search一.常用收集如下:(vi set)set autoindent     在插入模式下,对每行按与上行同样的标准进行缩进,与shiftwidth选项结 ...

  4. 第三周作业--Word Counter

    需求分析: 1.写出一个程序,模仿wc.exe,通过输入文件名,实现文件内容读取: 2.统计出文件内容的总字符数.总单词数.行数.每行字符数.每行单词数. 代码分析: 一.打开文件. FILE *fp ...

  5. MVC项目

    MVC 项目分析: 1.AssemblyInfo.cs  保存管理文件发布的一些属性和版本号 2.Content文件夹(保存相关的样式文件.CSS),scripts文件夹(保存相关的),fonts文件 ...

  6. 使用FreePic2Pdf导出书签至Word建立层级目录——快速初始化Word笔记本目录

    使用FreePic2Pdf导出书签至Word建立层级目录 --快速初始化Word笔记本目录 文:安徽师范大学2014级计算机科学与技术 王昊 (Get Contact:441301158@qq.com ...

  7. VB.net 调用dll

    Public Declare Function APlayer_OpenA Lib "APlayerCaller.dll" (ByVal aplayer As Integer, B ...

  8. JS实现的随机显示图片

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xht ...

  9. Oracle中分区表的使用

       查询分区:Select *From user_extents WHERE partition_name='分区名'; 1)创建表空间 create tablespace HRPM0 datafi ...

  10. ubuntu 安装mysql-python和 python-ldap,navicate 问题

    1.Ubuntu 下 pip install mysql-python 报错 EnvironmentError: mysql_config not found 原因是缺少mysqlclient 包,执 ...