jt
2021-06-10 5d0d028456874576560552f5a5c4e8b801786f11
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
 
namespace IFrame.Content.js.uploadify
{
    /// <summary>
    /// UploadHandlerWaterMark 的摘要说明
    /// </summary>
    public class UploadHandlerWaterMark : IHttpHandler
    {
 
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            try
            {
                string fileLogic = context.Request.QueryString["folder"] + "/";
                string strUploadPath = context.Request.PhysicalApplicationPath + context.Request.QueryString["folder"].Trim('/').Replace("/", "\\") + "\\";
                //创建路径
                if (!Directory.Exists(strUploadPath))
                {
                    Directory.CreateDirectory(strUploadPath);
 
                }
                string fileNameLogic = string.Empty;
                for (int i = 0; i < context.Request.Files.Count; i++)
                {
                    HttpPostedFile postedFile = context.Request.Files[i];
                    //获取扩展名
                    string fileExtension = System.IO.Path.GetExtension(postedFile.FileName).ToLower();
 
                    //string fileName = strUploadPath + Path.GetFileName(postedFile.FileName);
                    //生成随机名称
                    string fileRealName = "watermark" + fileExtension;//以GUID为文件重命名保证不会重复
                    //相对路径文件名称
                    fileNameLogic = fileLogic + fileRealName;
 
                    string fileName = strUploadPath + fileRealName;
                    //删除之前的水印文件
                    if (File.Exists(fileName))
                    {
                        File.Delete(fileName);
                    }
                    if (fileName != "")
                    {
                        postedFile.SaveAs(fileName);
 
                    }
                }
                context.Response.Write(fileNameLogic);
                //  context.Response.End();
 
            }
            catch (Exception ex)
            {
                context.Response.ContentType = "text/plain";
                context.Response.Write(ex.Message);
            } 
        }
 
       
 
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}