zoukankan      html  css  js  c++  java
  • .net文件上传,客户端用jquery file upload

    <%@ WebHandler Language="C#" Class="Handler" %>
    
    using System;
    using System.Web;
    
    
    using System.IO;
    
    
    public class Handler : IHttpHandler {
    
        /// <summary>
        /// 上传文件夹
        /// </summary>
        private const string UPLOAD_FOLDER = "~/UploadFile/";
    
        public void ProcessRequest(HttpContext context)
        {
            int resultVal = (int)ReturnVal.Failed;
            try
            {
                HttpPostedFile myFile = context.Request.Files[0];
    
                if (myFile != null)
                {
                    if (myFile.InputStream.Length != 0)
                    {
                        string originalFileName = Path.GetFileName(myFile.FileName);     //原文件名                        
                        string newFileName = string.Format("{0}_{1}", Guid.NewGuid(), originalFileName);   //新文件名---组成形式:  GUID + 下划线 + 原文件名
                        string fileAbsPath = context.Server.MapPath(UPLOAD_FOLDER) + newFileName;   //绝对路径
    
                        myFile.SaveAs(fileAbsPath);
    
                        resultVal = (int)ReturnVal.Succeed;
                    }
                    else
                    {
                        resultVal = (int)ReturnVal.FileEmpty;
                    }
                }
                else
                {
                    resultVal = (int)ReturnVal.NotSelected;
                }
            }
            catch (Exception)
            {
                resultVal = (int)ReturnVal.Failed;
            }
            finally
            {
                context.Response.Write(resultVal);
            }
        }
    
        #region## 返回值
        /// <summary>
        /// 返回值
        /// </summary>
        private enum ReturnVal : int
        {
            /// <summary>
            /// 不能上传 0 K大小的文件
            /// </summary>
            FileEmpty = -2,
    
            /// <summary>
            /// 未选中文件
            /// </summary>
            NotSelected = -1,
    
            /// <summary>
            /// 上传失败
            /// </summary>
            Failed = 0,
    
            /// <summary>
            /// 成功
            /// </summary>
            Succeed = 1
    
        }
        #endregion
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    
    }

  • 相关阅读:
    前端知识点(1)
    js防抖和节流
    react生命周期方法有哪些?
    vue音乐播放器
    vue天气查询
    vue+axios安装
    vue 实现todolist,包含添加,删除,统计,清空,隐藏功能
    vue简单计数器
    手动搭建的react环境中,关于图片引入的问题
    promise封装ajax
  • 原文地址:https://www.cnblogs.com/tongdengquan/p/6090518.html
Copyright © 2011-2022 走看看