近来把系统的编辑器换成了CKEditor,上传就得用自带的CKFinder,这个CKFinder还不错,但是不开源,还是收费的,不能部署到商业系统里.
于是抽空写了个XFinder,扩展了多文件上传,大文件上传,权限控制也比CKFinder灵活点.废话不说,先上图,界面有点丑,要用的兄弟自己改改
可多每个角色自定上传地址,文件后缀,文件正则,上传文件最大数,文件夹最大数,单文件尺寸现在,总文件容量限制,具体可以通过FileUploadSetting来设置,
[Serializable]
public class FileUploadSetting
{
public FileUploadOption option = (FileUploadOption)255;
/// <summary>
/// 最大文件数,-1为不限制
/// </summary>
public int FileMaximum = -1;
/// <summary>
/// 正则过滤后的最大文件数
/// </summary>
public int FileMaximumWithExpress = -1;
/// <summary>
/// 最大目录数
/// </summary>
public int DirectoryMaximum = -1;
/// <summary>
/// 正则过滤后的最大目录数
/// </summary>
public int DirectoryMaximumWithExpress = -1;
/// <summary>
/// 单个文件夹最大文件数,-1为不限制
/// </summary>
public long FileMaximumInDirectory = -1;
/// <summary>
/// 单个文件最大尺寸,-1为不限制
/// </summary>
public long FileSizeMaximum = -1;
/// <summary>
/// 单个文件最大尺寸,空字符串为不限制
/// </summary>
public string MaxFileSize
{
get
{
if (FileMaximum == -1)
{
return "0";
}
else
{
if (FileSizeMaximum / 1024 * 1024 * 1024 * 1024 >= 1)
{
return (((double)(FileSizeMaximum * 100 / 1024 * 1024 * 1024 * 1024)) / 100).ToString() + " TB";
}
else if (FileSizeMaximum / 1024 * 1024 * 1024 >= 1)
{
return (((double)(FileSizeMaximum * 100 / 1024 * 1024 * 1024)) / 100).ToString() + " GB";
}
else if (FileSizeMaximum / 1024 * 1024 >= 1)
{
return (((double)(FileSizeMaximum * 100 / 1024 * 1024)) / 100).ToString() + " MB";
}
else if (FileSizeMaximum / 1024 >= 1)
{
return (((double)(FileSizeMaximum * 100 / 1024)) / 100).ToString() + " KB";
}
else
{
return FileSizeMaximum.ToString() + " B";
}
}
}
set
{
if (new System.Text.RegularExpressions.Regex("^\\d+(b|k|m|g|t)$").IsMatch(value))
{
long size = long.Parse(value.Substring(0, value.Length - 2));
string unit = value.Substring(value.Length - 1);
switch (unit.ToLower())
{
case "b":
{
FileSizeMaximum = size;
break;
}
case "k":
{
FileSizeMaximum = size * 1024;
break;
}
case "m":
{
FileSizeMaximum = size * 1024 * 1024;
break;
}
case "g":
{
FileSizeMaximum = size * 1024 * 1024 * 1024;
break;
}
case "t":
{
FileSizeMaximum = size * 1024 * 1024 * 1024 * 1024;
break;
}
}
}
}
}
private string _rootdirectorypath;
/// <summary>
/// 根目录
/// </summary>
public string RootDirectoryPath
{
get
{
if (WebRootDirectoryPath != null)
{
return System.Web.HttpContext.Current.Server.MapPath(WebRootDirectoryPath);
}
else
{
return _rootdirectorypath;
}
}
set
{
_rootdirectorypath = value;
}
}
/// <summary>
/// 根目录(网站)
/// </summary>
public string WebRootDirectoryPath;
private string _rootdirectoryname;
/// <summary>
/// 根目录名称
/// </summary>
public string RootDirectoryName
{
get
{
if (_rootdirectoryname != null)
{
return _rootdirectoryname;
}
else if (System.IO.Directory.Exists(RootDirectoryPath))
{
return System.IO.Path.GetDirectoryName(RootDirectoryPath);
}
else
{
return "根目录";
}
}
set
{
_rootdirectoryname = value;
}
}
/// <summary>
/// 文件过滤后缀名,例如:"jpg,gif"
/// </summary>
public string FileExtension = "*";
private string _FileRegExpress;
/// <summary>
/// 文件正则,简单设置用FileExtension
/// </summary>
public string FileRegExpress
{
get
{
if (_FileRegExpress != null)
{
return _FileRegExpress;
}
else if (FileExtension != null && FileExtension != "*")
{
return ".+\\.(" + new ListPlus<string>(FileExtension.Split(',')).join("|") + ")$";
}
else
{
return "";
}
}
set
{
_FileRegExpress = value;
}
}
/// <summary>
/// 目录正则
/// </summary>
public string DirectoryRegExpress = "";
/// <summary>
/// 提示
/// </summary>
public string Note = "";
/// <summary>
/// 多选模式
/// </summary>
public bool MultipleModel = false;
/// <summary>
/// 允许自己输入地址
/// </summary>
public bool AllowInput = true;
public string Token = "";
//public string TokenName = "TAB_Users";
public FileUploadSetting() { }
public string GetEnCrypt()
{
System.IO.MemoryStream ms = new System.IO.MemoryStream();
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
bf.Serialize(ms, this);
string result = Convert.ToBase64String(ms.ToArray());
return EnCrypt.EncryptDES(result);
}
public static FileUploadSetting Parse(string serializstring)
{
string str = EnCrypt.DecryptDES(serializstring);
System.IO.MemoryStream ms = new System.IO.MemoryStream(Convert.FromBase64String(str));
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
ms.Position = 0;
FileUploadSetting c2 = (FileUploadSetting)bf.Deserialize(ms);
return c2;
}
/// <summary>
/// TAB_Users
/// </summary>
public static FileUploadSetting Debug
{
get
{
FileUploadSetting st = new FileUploadSetting();
st.RootDirectoryName = "根目录";
st.WebRootDirectoryPath = "/upload/";// "/Upload";
st.AllowInput = true;
st.FileExtension = "jpg,gif,jpeg,png,bmp";
st.Token = "Debug|0";
return st;
}
}
/// <summary>
/// TAB_Users
/// </summary>
public static FileUploadSetting WebManage
{
get
{
FileUploadSetting st = new FileUploadSetting();
st.RootDirectoryName = "根目录";
st.WebRootDirectoryPath = "/UF/A/";// "/Upload";
st.AllowInput = true;
st.FileExtension = "jpg,gif,jpeg,png,bmp";
st.Token = "AdminUser|0";
return st;
}
}
/// <summary>
/// TAB_Users
/// </summary>
public static FileUploadSetting Member(int id)
{
FileUploadSetting st = new FileUploadSetting();
st.RootDirectoryName = "我的资源库";
st.WebRootDirectoryPath = "/UF/M" + id.ToString() + "/";// "/Upload";
st.AllowInput = false;
st.FileExtension = "jpg,gif,jpeg,png,bmp";
st.MaxFileSize = "10 M";
st.MultipleModel = true;
st.Token = "Member|"+id;
st.option = FileUploadOption.DeleteFile | FileUploadOption.ReName | FileUploadOption.UploadFile | FileUploadOption.CreateDirectory | FileUploadOption.DeleteDirectory | FileUploadOption.ReNameDirectory;
st.Note = "文件最大尺寸10M";
return st;
}
/// <summary>
/// TAB_Users
/// </summary>
public static FileUploadSetting NonMember(int guid)
{
FileUploadSetting st = new FileUploadSetting();
st.RootDirectoryName = "临时资源库";
st.WebRootDirectoryPath = "/UF/T" + Math.Abs(guid) + "/";// "/Upload";
st.AllowInput = false;
st.FileExtension = "jpg,gif,jpeg,png,bmp";
st.FileMaximum = 4;
st.FileMaximumWithExpress = 4;
st.FileMaximumInDirectory = 4;
st.MaxFileSize = "1 M";
st.MultipleModel = true;
st.Token = "NonMember|"+guid.ToString();
st.option = FileUploadOption.DeleteFile | FileUploadOption.ReName | FileUploadOption.UploadFile;
st.Note = "非会员临时资源库最多允许上传4张图片,文件最大尺寸1M";
return st;
}
}
文件下载:HERE