Example of how jQuery uses uploadView to implement image preview upload function

黄舟
Release: 2017-08-11 13:56:35
Original
2222 people have browsed it

图片上传,网上有好多版本,今天小编给大家分享jquery.uploadView 实现图片预览上传功能,感兴趣的的朋友一起看看吧

图片上传,网上有好多版本,今天也要做一个查了好多最终找到了一个uploadview 进行了一下修改

来看代码


@{ Layout = null; }     Index   

示例

上传图片

Copy after login

代码前台看起来很简单。

实现的效果也还可以,不过这个保存的是base64的图片,插入数据库的时候我们一般都是保存xxxx.jpg 故需要实现一个方法


///  /// base64转图片 ///  ///  public static string BaseToImg(string baseimg) { byte[] bt = Convert.FromBase64String(baseimg.Replace("data:image/jpeg;base64,", "")); string filepath = "ImgServer".GetAppsetting(); string sqlurl = @"" + DateTime.Now.ToString("yyyyMMdd") + "\\"; string sqlname = "" + DateTime.Now.ToString("yyyyMMddhhmmssmsfff") + ".jpg"; if (!System.IO.File.Exists(filepath + sqlurl)) { System.IO.Directory.CreateDirectory(filepath + sqlurl); System.IO.File.WriteAllBytes(filepath + sqlurl + sqlname, bt); } return sqlurl + sqlname; }
Copy after login

这里我是根据日期对文件夹分组了,并且保存到数据库。避免单个文件太大

效果图类似这样

这个同样也适用于手机上

总结

The above is the detailed content of Example of how jQuery uses uploadView to implement image preview upload function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!