fineuploader使用实例
1、Fine Uploader特点
Fine Uploader Features:
A:支持文件上传进度显示.
B:文件拖拽浏览器上传方式
C:Ajax页面无刷新.
D:多文件上传.
F:跨浏览器.
E:跨后台服务器端语言.
2、页面前端代码
<div id="btnUpload"></div>
$(function () { $('#btnUpload').fineUploader({ request: { endpoint: 'Handler/UpLogo.ashx' }, validation: { allowedExtensions: ['jpeg', 'jpg', 'png'] }, multiple: false, text: { uploadButton: '<div>上传头像</div>' } }).on('complete', function (event, id, fileName, responseJson) { if (responseJson.success) { $("#absoluteUrl").val(responseJson.path); $("#jcrop_target").attr("src", responseJson.url); $("#jcrop_target").css({ "width": 300, "height": 300 }); $("#preview").attr("src", responseJson.url); $("#preview").css({ "width": 100, "height": 100 }); ias.update(); } }); });
2、Handler文件代码
<%@ WebHandler Language="C#" Class="UpLogo" %> using System; using System.Web; using System.IO; using System.Text; using System.Net; using System.Data; using System.Collections; using System.Collections.Generic; using System.Drawing; using ECS.Utility; public class UpLogo : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; if (context.Request != null && context.Request.Files.Count > 0) { var HttpFile = context.Request.Files[0]; var allowedExt = new List<string> { ".jpg", ".gif", ".bmp", ".png" }; var fileExt = Path.GetExtension(HttpFile.FileName).ToLower(); var File_Name = Path.GetFileNameWithoutExtension(HttpFile.FileName); var toFileName = Guid.NewGuid().ToString() + fileExt; var toFileFullPath = context.Server.MapPath("~/UpFiles/UserTemFace/"); var viewPath = "/UpFiles/UserTemFace/"; var Title = File_Name; DirectoryInfo di = new DirectoryInfo(toFileFullPath); if (!di.Exists) { di.Create(); } ECS.Model.A_User Model = new ECS.BLL.A_User().GetModel(ValUtil.GetUserID()); if (Model != null) { //toFileName = Model.UserFaceImg; string saveFile = toFileFullPath + toFileName; //先删除临时文件 //var _filePath = toFileFullPath + "\\" + toFileName; //if (File.Exists(_filePath)) //{ // FileInfo fi = new FileInfo(_filePath); // if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1) // { // fi.Attributes = FileAttributes.Normal; // } // File.Delete(_filePath); //} HttpFile.SaveAs(saveFile); Model.UserFaceImg = toFileName; new ECS.BLL.A_User().Update(Model); } string imgeUrl = ""; if (fileExt.ToLower().Equals(".jpg") || fileExt.ToLower().Equals(".gif") || fileExt.ToLower().Equals(".bmp") || fileExt.ToLower().Equals(".png")) { imgeUrl = viewPath + toFileName; } else { context.Response.Write("{success:false,msg:'只能上传图片类型的文件'}"); context.Response.End(); return; } string url = viewPath + "/" + toFileName; context.Response.Write(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(new { success = true, url = url, path = toFileName })); context.Response.End(); } else { context.Response.Write(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(new { success = false })); context.Response.End(); } } public bool IsReusable { get { return false; } } }

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
通过ajax记录网站UV、PV数
1、通过jquery记录网站UV、PV数据 util.track = { log: function () { var referrer = util.browser.getReferrer(), host = window.location.host, pathname = window.location.pathname, url = window.location.href, title = document.title, type = 0, itemId = null; var detailRegex = /\/item\/(\d+)/; if (detailRegex.test(pathname)) { var result = detailRegex.exec(pathname); itemId = result[1]; type = 1; $(".js_spec a").click(function () { setTimeout(function () { var skuId = $("#js_skuId").val(); if (skuId != itemId) { ...
- 下一篇
在 CentOS 6.4 上安装 CloudStack 4.2
在 CentOS 6.4上安装CloudStack 4.2 原文路径:http://www.vpsee.com/2013/11/install-cloudstack-4-2-on-centos-6-4/ 和 OpenStack,OpenNebula 类似,CloudStack是另一款开源云计算平台。CloudStack的前身是 Cloud.com 家的一款商业云计算产品(也有开源版本),2011年 Cloud.com 被Citrix 收购,2012年的时候 Citrix 将收购的云平台 CloudStack 全部捐给了 Apache 基金会,自己则以 Citrix CloudPlatform (powered by Apache CloudStack) 的形式为客户提供商业化的云计算解决方案。 按照《OpenStack,OpenNebula, Eucalyptus, CloudStack社区活跃度比较》的统计,貌似 CloudStack 项目的活跃程度仅次于 OpenStack. 和大多数云计算、集群软件一样,CloudStack 也是控制节点+计算节点这种架构,控制节点(clouds...
相关文章
文章评论
共有0条评论来说两句吧...