Control/UpLoadFile.cs
(开头部分) 11KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Common;
using Config;
using Entity;
using System.Web;
namespace Controller
{
/// <summary>
/// 上传文件操作类
/// </summary>
public class UpLoadFile
{
private static string FileType = ".rar";//可用的文件类型
/// <summary>
/// 上传文件,返回消息,返回附件FileSize,Attachment,FileName,FileType
/// </summary>
/// <param name="fileUpload"></param>
/// <param name="m_message"></param>
/// <param name="attach"></param>
/// <returns></returns>
public static bool UpLoad(HttpPostedFile myFile, ref string m_message, ref AttachmentInfo attach)
{
string mPath = GetUploadFolder("uploadfile");
if (myFile != null)
{
int nFileLen = myFile.ContentLength;
if (nFileLen == 0)
{
m_message = "<br /><font color=red>没有选定被上传的文件</font></b>";
return false;
}
//比较扩展名
FileType = AttachmentConfigManager.AttachConfig.UploadFileType;//可用的文件类型
string fileExtendName = Path.GetExtension(myFile.FileName).ToLower();//
if (FileType.IndexOf(fileExtendName) < 0)
{
m_message = "文件必须是以" + FileType.Replace("|", " , ") + "为扩展名的文件";
return false;
}
byte[] myData = new Byte[nFileLen];
myFile.InputStream.Read(myData, 0, nFileLen);
//为文件重命名为日期格式
DateTime filenamedate = DateTime.Now;
Random ran = new Random();
string sFilename = filenamedate.Hour.ToString() + "-" + filenamedate.Minute.ToString() + "-" + filenamedate.Second.ToString() + ran.Next(1000, 2000) + fileExtendName;
attach.Filesize = StrTools.ByteToString(myFile.ContentLength);
attach.Attachment =Path.GetFileName(myFile.FileName) ;
attach.Filetype = fileExtendName;
int file_append = 0;
//看是否已存在文件
while (File.Exists(mPath + sFilename))
后面还有 222 行代码,购买后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
