⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uploader.cs

📁 动易SiteFactory&#8482 网上商店系统1.0源代码
💻 CS
字号:
namespace PowerEasy.Controls.Editor
{
    using PowerEasy.Common;
    using PowerEasy.CommonModel;
    using PowerEasy.Components;
    using PowerEasy.Model.CommonModel;
    using System;
    using System.Collections.Generic;
    using System.Configuration;
    using System.IO;
    using System.Web;

    public class Uploader : FileWorkerBase
    {
        private static string GetAllowSuffix(FieldInfo fieldInfo, string uploaderType)
        {
            string str2;
            string str3;
            string str4;
            string str = "";
            if (fieldInfo.Settings.Count > 9)
            {
                str2 = fieldInfo.Settings[6];
                str3 = fieldInfo.Settings[7];
                str4 = fieldInfo.Settings[8];
            }
            else
            {
                str2 = fieldInfo.Settings[2];
                str3 = fieldInfo.Settings[3];
                str4 = fieldInfo.Settings[4];
            }
            string str5 = uploaderType;
            if (str5 == null)
            {
                return str;
            }
            if (!(str5 == "Photo"))
            {
                if ((str5 == "Flash") || (str5 == "Media"))
                {
                    return str3;
                }
                if (str5 != "Link")
                {
                    return str;
                }
                return str4;
            }
            return str2;
        }

        protected override void OnLoad(EventArgs e)
        {
            HttpPostedFile file = base.Request.Files["NewFile"];
            string str = Path.GetExtension(file.FileName).ToLower();
            string uploaderType = base.Request.Form["UploaderType"];
            bool flag = DataConverter.CBool(base.Request.Form["IsWatermark"]);
            bool flag2 = DataConverter.CBool(base.Request.Form["IsThumb"]);
            int modelId = DataConverter.CLng(base.Request.Form["ModelId"]);
            string str3 = DataSecurity.FilterBadChar(base.Request.Form["FieldName"]);
            string allowSuffix = "";
            int uploadFileMaxSize = 0;
            string customMsg = "请检查网站信息配置是否设置允许的上传文件大小!";
            if (!PEContext.Current.Admin.Identity.IsAuthenticated && !PEContext.Current.User.Identity.IsAuthenticated)
            {
                this.SendResults(0xcc);
            }
            else if (!SiteConfig.SiteOption.EnableUploadFiles)
            {
                this.SendResults(0xcc);
            }
            else if ((file == null) || (file.ContentLength == 0))
            {
                this.SendResults(0xca);
            }
            else
            {
                if ((modelId == 0) || string.IsNullOrEmpty(str3))
                {
                    if (!ConfigurationManager.AppSettings["PowerEasy:DefaultUploadSuffix"].ToLower().Contains(str))
                    {
                        this.SendResults(1, "", "", "不允许上传动态页文件!");
                        return;
                    }
                    uploadFileMaxSize = SiteConfig.SiteOption.UploadFileMaxSize;
                }
                else
                {
                    IList<FieldInfo> fieldListByModelId = ModelManager.GetFieldListByModelId(modelId);
                    if ((fieldListByModelId != null) && (fieldListByModelId.Count > 0))
                    {
                        foreach (FieldInfo info in fieldListByModelId)
                        {
                            if (info.FieldName.CompareTo(str3) == 0)
                            {
                                allowSuffix = GetAllowSuffix(info, uploaderType);
                                if (info.Settings.Count > 7)
                                {
                                    uploadFileMaxSize = DataConverter.CLng(info.Settings[7]);
                                }
                                break;
                            }
                        }
                    }
                    if (string.IsNullOrEmpty(allowSuffix))
                    {
                        this.SendResults(1, "", "", "字段内容控件没有填写允许上传的后缀!");
                        return;
                    }
                    if (!allowSuffix.Contains(str.Replace(".", "")))
                    {
                        this.SendResults(1, "", "", "这种文件类型不允许上传!只允许上传这几种文件类型:" + allowSuffix);
                        return;
                    }
                    customMsg = "请检查所属字段控件是否设置了允许上传文件大小!";
                }
                if (uploadFileMaxSize <= 0)
                {
                    this.SendResults(1, "", "", customMsg);
                }
                else if (file.ContentLength > (uploadFileMaxSize * 0x400))
                {
                    this.SendResults(1, "", "", "请上传小于" + uploadFileMaxSize.ToString() + "KB的文件!");
                }
                else
                {
                    string str9;
                    int errorNumber = 0;
                    string fileUrl = "";
                    string str7 = DataSecurity.MakeFileRndName();
                    string str8 = str7 + str;
                    int num4 = 0;
                    while (true)
                    {
                        str9 = Path.Combine(base.UserFilesDirectory, str8);
                        if (!File.Exists(str9))
                        {
                            break;
                        }
                        num4++;
                        str8 = string.Concat(new object[] { Path.GetFileNameWithoutExtension(file.FileName), "(", num4, ")", Path.GetExtension(file.FileName) });
                        errorNumber = 0xc9;
                    }
                    file.SaveAs(str9);
                    fileUrl = base.UserFilesPath + str8;
                    if (!string.IsNullOrEmpty(uploaderType) && (uploaderType.CompareTo("Photo") == 0))
                    {
                        string oldValue = "";
                        if (base.Request.ApplicationPath.EndsWith("/"))
                        {
                            oldValue = ("/" + SiteConfig.SiteOption.UploadDir + "/").Replace("//", "/");
                        }
                        else
                        {
                            oldValue = base.Request.ApplicationPath + "/" + SiteConfig.SiteOption.UploadDir;
                        }
                        if (flag)
                        {
                            WaterMark.AddWaterMark(fileUrl.Replace(oldValue, ""));
                        }
                        if (flag2)
                        {
                            string str11 = base.UserFilesPath + str7 + "_S" + str;
                            Thumbs.GetThumbsPath(fileUrl.Replace(oldValue, ""), str11.Replace(oldValue, ""));
                        }
                    }
                    this.SendResults(errorNumber, fileUrl, str8);
                }
            }
        }

        private void SendResults(int errorNumber)
        {
            this.SendResults(errorNumber, "", "", "");
        }

        private void SendResults(int errorNumber, string fileUrl, string fileName)
        {
            this.SendResults(errorNumber, fileUrl, fileName, "");
        }

        private void SendResults(int errorNumber, string fileUrl, string fileName, string customMsg)
        {
            base.Response.Clear();
            base.Response.Write("<script type=\"text/javascript\">");
            base.Response.Write(string.Concat(new object[] { "window.parent.OnUploadCompleted(", errorNumber, ",'", fileUrl.Replace("'", @"\'"), "','", fileName.Replace("'", @"\'"), "','", customMsg.Replace("'", @"\'"), "') ;" }));
            base.Response.Write("</script>");
            base.Response.End();
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -