温馨提示:代码在线浏览功能只能做为源码浏览参考,不能展示项目的全部,如果想更进一步了解该代码请下载:NETCMSv1.5(Build0509)完整源码版
当前文件路径:NetCMSv15/NetCMS.Content/Common/UpLoad.cs

1//====================================================== 2
//== (c)2008 aspxcms inc by NeTCMS v1.0 == 3
//== Forum:bbs.aspxcms.com == 4
//== Website:www.aspxcms.com == 5
//====================================================== 6
using System; 7
using System.Collections.Generic; 8
using System.Text; 9
using System.IO; 10
using System.Data; 11
12
namespace NetCMS.Content.Common 13
{ 14
public class UpLoad 15
{ 16
private System.Web.HttpPostedFile postedFile = null; 17
private string savePath = ""; 18
private string extension = ""; 19
private int fileLength = 0; 20
21
/// <summary> 22
/// 显示该组件使用的参数信息 23
/// </summary> 24
public System.Web.HttpPostedFile PostedFile 25
{ 26
get 27
{ 28
return postedFile; 29
} 30
set 31
{ 32
postedFile = value; 33
} 34
} 35
public string SavePath 36
{ 37
get 38
{ 39
if (savePath != "") return savePath; 40
return "c:\\"; 41
} 42
set 43
{ 44
savePath = value; 45
} 46
} 47
public int FileLength 48
{ 49
get 50
{ 51
if (fileLength != 0) return fileLength; 52
return 1024; 53
} 54
set 55
{ 56
fileLength = value * 1024; 57
} 58
} 59
60
public string Extension 61
{ 62
get 63
{ 64
if (extension != "") 65
return extension; 66
return "txt"; 67
} 68
set 69
{ 70
extension = value; 71
} 72
} 73
public string PathToName(string path) 74
{ 75
int pos = path.LastIndexOf(@"\"); 76
return path.Substring(pos + 1); 77
} 78
/// <summary> 79
/// 上传文件 80
/// </summary> 81
/// <returns></returns> 82
public string Upload(int _num,int isAdmin) 83
{ 84
if (PostedFile != null) 85
{ 86
int getFileLent=0; 87
try 88
{ 89
//此处得到会员所在的会员组的上传信息 90
if (isAdmin != 1) 91
{ 92
rootPublic pd = new rootPublic(); 93
DataTable dt = pd.getGroupUpInfo(NetCMS.Global.Current.UserNum); 94
if (dt != null && dt.Rows.Count > 0) 95
{ 96
Extension = dt.Rows[0]["upfileType"].ToString(); 97
getFileLent = int.Parse(dt.Rows[0]["upfileSize"].ToString()) * 1024; 98
} 99
} 100
else{getFileLent = FileLength;} 101
string fileName = PathToName(PostedFile.FileName); 102
string _fileName = ""; 103
string[] Exten = Extension.Split(','); 104
if (Exten.Length == 0){return "你未设置上传文件类型,系统不允许进行下一步操作!$0";} 105
else 106
{ 107
for (int i = 0; i < Exten.Length; i++) 108
{ 109
if (fileName.ToLower().EndsWith(Exten[i].ToLower())) 110
{ 111
if (PostedFile.ContentLength > getFileLent) return "上传文件限制大小:" + getFileLent / 1024 + "kb!$0"; 112
string IsFileex = SavePath + @"\" + fileName; 113
if (!Directory.Exists(SavePath)) { Directory.CreateDirectory(SavePath); } 114
if (_num == 1) 115
{ 116
string _Randstr = NetCMS.Common.Rand.Number(6); 117
string _tmps = DateTime.Now.Month + DateTime.Now.Day + "-" + _Randstr + "-" + fileName; 118
if (File.Exists(IsFileex)) 119
{ 120
postedFile.SaveAs(SavePath + @"" + _tmps); 121
_fileName = _tmps; 122
return _fileName + "$1"; 123
} 124
else 125
{ 126
PostedFile.SaveAs(IsFileex); 127
_fileName = fileName; 128
return _fileName + "$1"; 129
} 130
} 131
else 132
{ 133
PostedFile.SaveAs(IsFileex); 134
_fileName = fileName; 135
return _fileName + "$1"; 136
} 137
} 138
} 139
return "只允许上传" + Extension + " 文件!$0"; 140
} 141
} 142
catch (System.Exception exc) 143
{ 144
return exc.Message + "$0"; 145
} 146
} 147
else 148
{ 149
return "上文件失败!$0"; 150
} 151
} 152
153
} 154
} 155





}