NBIbatis.WX/FileUploadServer.ashx

(开头部分) 3KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

<%@ WebHandler Language="C#" CodeBehind="FileUploadServer.ashx.cs" Class="UploadHandler.FileUploadServer" %>
namespace UploadHandler
{
    using System;
    using System.Collections.Generic;
    using System.Web;
    using System.IO;
    using System.Web.Services;

    /// <summary>
    /// 上传文件
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class FileUploadServer : IHttpHandler
    {
        private HttpContext _context;
        public void ProcessRequest(HttpContext context)
        {
            _context = context;

            string src = context.Request.Form["src"];
            if (string.IsNullOrEmpty(src)) return;

            src = src.ToLower();
            //bool isExtValid = src.EndsWith(".jpg") || src.EndsWith(".png") || src.EndsWith(".gif") || src.EndsWith(".bmp") || src.EndsWith(".jpeg");
            //if (isExtValid)
            //{
            context.Response.ContentType = "text/plain";
            string ext = context.Request.Form["ext"];
            string content = context.Request.Form["data"];
            string filename = context.Request.Form["src"];
            Upload(filename, content);
            //}
        }
        /// <summary>
        /// 文件上传
        /// </summary>
        /// <param name="fileName">文件名</param>
        /// <param name="content">内容</param>
        private void Upload(string fileName, string content)
        {
            if (string.IsNullOrEmpty(fileName) || string.IsNullOrEmpty(content))
            {
                return;
            }
            //处理文件路径
            DateTime now = DateTime.Now;
            string relativePath = "upload\\" + now.ToString("yyyyMM") + "\\" + now.Day.ToString("00") + "\\";
            string currentPath = HttpContext.Current.Request.PhysicalApplicationPath + relativePath;
            string fullPath = currentPath + fileName;

            if (!Directory.Exists(currentPath))
                Directory.CreateDirectory(currentPath);

            //保存文件
            byte[] buffer = Convert.FromBase64String(content);
            using (FileStream fileStream = new FileStream(fullPath, FileMode.Create))
            {
                fileStream.Write(buffer, 0, buffer.Length);
后面还有 28 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。