上传图片 £神魔★判官ぃ 2021-09-30 09:54 577阅读 0赞 <img src="~/Content/img/btn\_1.png" class="img-responsive" id="a\_pic"> <input class="btn\_upimg" type="file" /> $(".btn\_upimg").change(function () \{ var $img = $(this).prev(); console.log($(this).prop('files')) if ($(this).prop('files').length === 0) \{ alert("请选择图片"); return; \} var oFile = $(this).prop('files')\[0\]; if (!new RegExp("(jpg|jpeg|png)+", "gi").test(oFile.type)) \{ alert("照片上传:文件类型必须是JPG、JPEG、PNG"); return; \} var reader = new FileReader(); reader.onload = function (e) \{ var base64Img = e.target.result; //压缩前预览 console.log(base64Img) $img.attr("src", base64Img); $.post("/LotteryDraw/uploadImg", \{ img: base64Img \}, function (data) \{ var obj = eval('(' + data + ')') if (obj.Error\_code ==="I2001") \{ $img.attr("success\_src", obj.Data.img\_stc); $img.next().next().hide(); \} else \{ $img.next().next().show(); \} console.log(obj); \}) \}; reader.readAsDataURL(oFile); \}) public string uploadImg(string img) \{ //string imgsrc = UpImg(img); Pacific.PoubtsShop.Common.ResultJsonInfo<imgJson> s = new PoubtsShop.Common.ResultJsonInfo<imgJson>(); imgJson imgsrc = new imgJson(); imgsrc.img\_stc = UpImg(img); s.Status = 0; if (imgsrc.img\_stc=="") \{ s.Msg = "图片上传失败!"; s.Error\_code = "I4001"; \} else \{ s.Msg = "图片上传成功!"; s.Error\_code = "I2001"; \} s.Data = imgsrc; return JsonConvert.SerializeObject(s); \} public class imgJson \{ public string img\_stc \{ get; set; \} \} /// <summary> /// 图片上传保存 /// </summary> /// <param name="strbase64"></param> /// <returns></returns> public string UpImg(string strbase64) \{ try \{ string imgType = strbase64.Split(';')\[0\]; imgType = imgType.Split('/')\[1\]; strbase64 = strbase64.Split(',')\[1\]; byte\[\] arr = Convert.FromBase64String(strbase64); MemoryStream ms = new MemoryStream(arr); Bitmap bmp = new Bitmap(ms); string path = "\\\\upload\\\\img\\\\"; string tmpRootDir = System.Web.HttpContext.Current.Server.MapPath(System.Web.HttpContext.Current.Request.ApplicationPath.ToString());//获取程序根目录 string imageUrl = tmpRootDir + path.Replace(@"/", @"\\"); //转换成绝对路径 string imageName = ""; if (imgType.ToLower() == "png") \{ imageName = DateTime.Now.ToString("yyyyMMddHHmmss\_ffff", DateTimeFormatInfo.InvariantInfo) + ".png"; bmp.Save(imageUrl + imageName, ImageFormat.Png); \} else if (imgType.ToLower() == "gif") \{ imageName = DateTime.Now.ToString("yyyyMMddHHmmss\_ffff", DateTimeFormatInfo.InvariantInfo) + ".gif"; bmp.Save(imageUrl + imageName, ImageFormat.Gif); \} else if (imgType.ToLower() == "bmp") \{ imageName = DateTime.Now.ToString("yyyyMMddHHmmss\_ffff", DateTimeFormatInfo.InvariantInfo) + ".bmp"; bmp.Save(imageUrl + imageName, ImageFormat.Bmp); \} else if (imgType.ToLower() == "jpeg") \{ imageName = DateTime.Now.ToString("yyyyMMddHHmmss\_ffff", DateTimeFormatInfo.InvariantInfo) + ".jpg"; bmp.Save(imageUrl + imageName, System.Drawing.Imaging.ImageFormat.Jpeg); \} //bmp.Save(imageUrl+"test.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); //bmp.Save("test.bmp", ImageFormat.Bmp); //bmp.Save("test.gif", ImageFormat.Gif); ms.Close(); return "/upload/img/" + imageName; // Context.Response.Write("\{\\"status\\":1,\\"message\\":\\"" + bmp + "\\"\}"); \} catch (Exception e) \{ return ""; //Context.Response.Write("\{\\"status\\":1,\\"message\\":\\"操作错误!\\"\}"); \} \} 转载于:https://www.cnblogs.com/ztf20/p/9886093.html
相关 apiclod 上传图片_apiCloud上传图片 Hello APP height:100%; \} \wrap\{ height:100%; display:-webkit-box; display:-webki 野性酷女/ 2022年10月31日 00:57/ 0 赞/ 247 阅读
相关 图片上传 [AngularJS图片上传功能的实现][AngularJS] 一、前言 前一段时间做项目时,遇到一个问题就是AngularJS实现图片预览和上传的功能,当时查阅文档(都是 痛定思痛。/ 2022年06月05日 00:48/ 0 赞/ 232 阅读
相关 图片上传 上篇博客已经介绍了文件的上传,这次就简单总结一下图片的上传,以及上传图片的显示。 利用三个控件:Input(File)、Button控件、Image控件,页面简单设计如下图: 川长思鸟来/ 2022年06月03日 08:26/ 0 赞/ 228 阅读
相关 图片上传 1, 定义模型 class UserLearn(models.Model): u_name = models.CharField(max_length=16) u_i 缺乏、安全感/ 2022年06月03日 02:27/ 0 赞/ 246 阅读
相关 图片上传 html <button type="button" class="btn btn-primary" οnclick="F\_Open\_dialog2()">Impor 小咪咪/ 2022年06月01日 14:24/ 0 赞/ 265 阅读
相关 图片上传 文件上传流程: 1、定义 <input type="file" name="file" accept="image/\" onchange="uploadimage(th ゝ一世哀愁。/ 2022年04月02日 11:46/ 0 赞/ 325 阅读
相关 上传图片 开发工具与关键技术:Visual Studio 作者:肖广斌 撰写时间:2019年5月12日 在做项目时,我们在完善一些个人信息、或者一些页面时,我们需要用到图片, 本是古典 何须时尚/ 2022年01月31日 12:45/ 0 赞/ 295 阅读
相关 上传图片 @Service public class FileServiceImpl implements FileService { privat 柔情只为你懂/ 2021年12月23日 13:47/ 0 赞/ 385 阅读
相关 上传图片 <img src="~/Content/img/btn\_1.png" class="img-responsive" id="a\_pic"> <input class=" £神魔★判官ぃ/ 2021年09月30日 09:54/ 0 赞/ 578 阅读
相关 上传图片 // 允许上传的图片后缀 $allowedExts = array("gif", "jpeg", "jpg", "png"); $temp = expl 蔚落/ 2021年09月18日 22:22/ 0 赞/ 513 阅读
还没有评论,来说两句吧...