fineuploader使用实例

简介: 1、Fine Uploader特点 Fine Uploader Features: A:支持文件上传进度显示. B:文件拖拽浏览器上传方式 C:Ajax页面无刷新.

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;
        }
    }

}


目录
相关文章
|
传感器 监控 物联网
golang开源的可嵌入应用程序高性能的MQTT服务
golang开源的可嵌入应用程序高性能的MQTT服务
1311 3
|
7月前
|
消息中间件 人工智能 NoSQL
2026实战:用ChatGPT官网设计高可用秒杀系统架构
本文介绍AI(如GPT-4o)如何高效辅助技术架构师设计高并发秒杀系统:3秒生成含限流、Redis原子扣减、RocketMQ异步下单、分库分表等的完整方案,覆盖技术选型、伪代码、风险点及文档输出,将2人天工作压缩至2小时内,提升设计效率与质量。(239字)
|
安全 Java 持续交付
如何实现上传jar直接部署成功,这篇文章直接带你上手springboot实现jar包热更新!
本文详细讲解了在Spring Boot应用中实现Jar包热更新的实践方法。通过自定义类加载器(`HotClassLoader`),动态加载和卸载指定目录下的Jar包,结合Spring Bean动态注册机制,使新加载的类能够被Spring容器管理。同时,提供了文件上传接口,方便用户手动触发Jar包更新。文章还强调了安全性、依赖管理和线程安全等注意事项,并给出了测试步骤和总结,帮助开发者高效实现热更新功能,减少服务中断和提升开发效率。
|
人工智能 安全 API
最近谈论 SSE 和 WebSocket 的人越来越多的原因
实时通信已经成了大模型应用的标配。
2901 273
最近谈论 SSE 和 WebSocket 的人越来越多的原因
|
缓存 监控 Linux
Linux系统清理缓存(buff/cache)的有效方法。
总结而言,在大多数情形下你不必担心Linux中buffer与cache占用过多内存在影响到其他程序运行;因为当程序请求更多内存在没有足够可用资源时,Linux会自行调整其占有量。只有当你明确知道当前环境与需求并希望立即回收这部分资源给即将运行重负载任务之前才考虑上述方法去主动干预。
2802 10
|
10月前
|
运维 监控 安全
单点登录SSO最佳实践:加强安全性与简化访问流程
单点登录(SSO)技术凭借“一套凭证畅行多个应用”的核心特性,极大简化了用户的登录操作。不过,SSO 在提升便捷性的同时,也将关键系统的访问入口集中化,因此必须落实一系列最佳实践,才能切实守护用户凭证与敏感数据的安全。
333 0
|
消息中间件 Java RocketMQ
低版本的springboot(1.5.3)如何集成rocketmq
低版本的springboot(1.5.3)如何集成rocketmq
735 1
spring boot中shiro使用自定义注解屏蔽接口鉴权
传统做法 spring boot整合shiro后,如果某些接口需要屏蔽鉴权的话(比如登录)接口,我们一般会这么做:
|
域名解析 网络协议 数据建模
通配符SSL证书申请教程
本文介绍了如何申请和安装通配符SSL证书的步骤:首先选择DV类型的通配符SSL证书并生成CSR,建议使用DNS方式进行验证,随后在域名注册商处添加相应解析记录,待验证通过后,即可下载SSL证书,整个过程大约需要10-15分钟。
1141 7

热门文章

最新文章