/// <summary> /// 产生附件 /// </summary> /// <param name="attachmentinfo">附件描述类数组</param> /// <returns>附件id数组</returns> public static int[] CreateAttachments(AttachmentInfo[] attachmentinfo) { int acount = attachmentinfo.Length; int icount = 0; int tid = 0; int pid = 0; int[] aid = new int[acount]; int attType = 1;//普通附件,2为图片附件 for (int i = 0; i < acount; i++) { if (attachmentinfo[i] != null && attachmentinfo[i].Sys_noupload.Equals("")) { aid[i] = DatabaseProvider.GetInstance().CreateAttachment(attachmentinfo[i]); icount ++ ; tid = attachmentinfo[i].Tid; pid = attachmentinfo[i].Pid; attachmentinfo[i].Aid = aid[i]; if (attachmentinfo[i].Filetype.ToLower().StartsWith("image")) attType = 2; } } if (icount > 0) { DatabaseProvider.GetInstance().UpdateTopicAttachmentType(tid, attType); DatabaseProvider.GetInstance().UpdatePostAttachmentType(pid, Posts.GetPostTableID(tid), attType); } return aid; }
/// <summary> /// 产生附件 /// </summary> /// <param name="attachmentinfo">附件描述类数组</param> /// <returns>附件id数组</returns> public static int[] CreateAttachments(AttachmentInfo[] attachmentinfo) { int acount = attachmentinfo.Length; int icount = 0; int tid = 0; int pid = 0; int[] aid = new int[acount]; int attType = 1;//普通附件,2为图片附件 for (int i = 0; i < acount; i++) { if (attachmentinfo[i] != null && attachmentinfo[i].Sys_noupload.Equals("")) { aid[i] = Discuz.Data.Attachments.CreateAttachments(attachmentinfo[i]); icount++; tid = attachmentinfo[i].Tid; pid = attachmentinfo[i].Pid; attachmentinfo[i].Aid = aid[i]; if (attachmentinfo[i].Filetype.ToLower().StartsWith("image")) attType = 2; } } if (icount > 0) UpdateTopicAndPostAttachmentType(tid, pid, attType); return aid; }
/// <summary> /// 产生附件 /// </summary> /// <param name="attachmentinfo">附件描述类</param> /// <returns>附件id</returns> public static int CreateAttachments(AttachmentInfo attachmentinfo) { attachmentinfo.Aid = DatabaseProvider.GetInstance().CreateAttachment(attachmentinfo); if (appDBCache) IAttachmentService.CreateAttachments(attachmentinfo); return attachmentinfo.Aid; }
protected override void OnTopicCreated(TopicInfo topic, PostInfo post, AttachmentInfo[] attachs) { SpacePostInfo spacepost = new SpacePostInfo(); spacepost.Author = post.Poster; string content = Posts.GetPostMessageHTML(post, attachs); spacepost.Category = ""; spacepost.Content = content; spacepost.Postdatetime = DateTime.Now; spacepost.PostStatus = 1; spacepost.PostUpDateTime = DateTime.Now; spacepost.Title = post.Title; spacepost.Uid = post.Posterid; DbProvider.GetInstance().AddSpacePost(spacepost); }
/// <summary> /// 绑定附件数组中的参数,返回新上传的附件个数 /// </summary> /// <param name="attachmentInfo">提交的附件列表</param> /// <param name="topicId">当前主题id</param> /// <param name="postId">当前帖子id</param> /// <param name="userId">当前用户id</param> /// <param name="userGroupInfo">当前用户用户组</param> /// <returns></returns> public static int BindAttachment(AttachmentInfo[] attachmentInfo, int topicId, int postId, int userId, UserGroupInfo userGroupInfo) { //附件阅读权限 //string[] readperm = String.IsNullOrEmpty(DNTRequest.GetString("readperm")) ? null : DNTRequest.GetString("readperm").Split(','); //string[] attachdesc = DNTRequest.GetString("attachdesc") == null ? null : DNTRequest.GetString("attachdesc").Split(','); //string[] localid = DNTRequest.GetString("localid") == null ? null : DNTRequest.GetString("localid").Split(','); ////附件价格 //string[] attachprice = DNTRequest.GetString("attachprice") == null ? null : DNTRequest.GetString("attachprice").Split(','); int newAttachCount = 0; int i_readperm = 0; for (int i = 0; i < attachmentInfo.Length; i++) { if (attachmentInfo[i] == null) continue; if (attachmentInfo[i].Pid == 0)//如果附件pid=0,就代表它是新上传的附件 newAttachCount++; string aid = attachmentInfo[i].Aid.ToString(); attachmentInfo[i].Uid = userId; attachmentInfo[i].Tid = topicId; attachmentInfo[i].Pid = postId; attachmentInfo[i].Postdatetime = Utils.GetDateTime(); attachmentInfo[i].Readperm = 0; //attachmentInfo[i].Attachprice = attachprice != null ? UserGroups.CheckUserGroupMaxPrice(userGroupInfo, Utils.StrToInt(attachprice[i], 0)) : 0; int attachprice = Utils.StrToInt(DNTRequest.GetString("attachprice_" + aid),0); attachmentInfo[i].Attachprice = attachprice == 0 ? 0 : UserGroups.CheckUserGroupMaxPrice(userGroupInfo, attachprice); int readperm = Utils.StrToInt(DNTRequest.GetString("readperm_" + aid), 0); if (readperm != 0) { i_readperm = readperm; //当为最大阅读仅限(255)时 i_readperm = i_readperm > 255 ? 255 : i_readperm; attachmentInfo[i].Readperm = i_readperm; } //if (attachdesc != null && !attachdesc[i].Equals("")) attachmentInfo[i].Description = Utils.HtmlEncode(DNTRequest.GetString("attachdesc_" + aid)); } return newAttachCount; }
/// <summary> /// 将单个附件DataRow转换为AttachmentInfo类 /// </summary> /// <param name="drAttach">单个附件DataRow</param> /// <param name="drAttach">是否返回原始路径</param> /// <returns>AttachmentInfo类</returns> private static AttachmentInfo LoadSingleAttachmentInfo(IDataReader drAttach, bool isOriginalFilename) { AttachmentInfo attach = new AttachmentInfo(); if (drAttach.Read()) { attach.Aid = TypeConverter.ObjectToInt(drAttach["aid"]); attach.Uid = TypeConverter.ObjectToInt(drAttach["uid"]); attach.Tid = TypeConverter.ObjectToInt(drAttach["tid"]); attach.Pid = TypeConverter.ObjectToInt(drAttach["pid"]); attach.Postdatetime = drAttach["postdatetime"].ToString(); attach.Readperm = TypeConverter.ObjectToInt(drAttach["readperm"]); if (isOriginalFilename) { attach.Filename = drAttach["filename"].ToString(); } else if (drAttach["filename"].ToString().Trim().ToLower().IndexOf("http") < 0) { attach.Filename = BaseConfigs.GetForumPath + "upload/" + drAttach["filename"].ToString().Trim().Replace("\\", "/"); } else { attach.Filename = drAttach["filename"].ToString().Trim().Replace("\\", "/"); } attach.Description = drAttach["description"].ToString().Trim(); attach.Filetype = drAttach["filetype"].ToString().Trim(); attach.Attachment = drAttach["attachment"].ToString().Trim(); attach.Filesize = TypeConverter.ObjectToInt(drAttach["filesize"]); attach.Downloads = TypeConverter.ObjectToInt(drAttach["downloads"]); attach.Attachprice = TypeConverter.ObjectToInt(drAttach["attachprice"], 0); attach.Height = TypeConverter.ObjectToInt(drAttach["height"]); attach.Width = TypeConverter.ObjectToInt(drAttach["width"], 0); attach.Isimage = TypeConverter.ObjectToInt(drAttach["isimage"], 0); } drAttach.Close(); return attach; }
/// <summary> /// 附件操作 /// </summary> /// <param name="attachmentinfo">附件信息</param> /// <param name="topicId">主题id</param> /// <param name="postId">帖子id</param> /// <param name="postInfo">帖子信息</param> /// <param name="returnMsg">返回信息</param> /// <param name="userId">当前用户id</param> /// <param name="config">配置信息</param> /// <param name="userGroupInfo">当前用户组信息</param> /// <returns></returns> public static bool UpdateAttachment(AttachmentInfo[] attachmentArray, int topicId, int postId, PostInfo postInfo, ref StringBuilder returnMsg, int userId, GeneralConfigInfo config, UserGroupInfo userGroupInfo) { if (attachmentArray == null) return false; if (attachmentArray.Length > config.Maxattachments) { //returnMsg = new StringBuilder("系统设置为每个帖子附件不得多于" + config.Maxattachments + "个"); returnMsg = new StringBuilder(); returnMsg.AppendFormat("您添加了{0}个图片/附件,多于系统设置的{1}个.<br/>请重新编辑该帖并删除多余图片/附件.", attachmentArray.Length, config.Maxattachments); return false; } int newAttachCount = Attachments.BindAttachment(attachmentArray, topicId, postId, userId, userGroupInfo); //int errorAttachment = Attachments.BindAttachment(attachmentinfoarray, postid, sb, topicid, userid, usergroupinfo, out newAttachCount); int[] aid = new int[attachmentArray.Length]; int attType = 0;//普通附件,2为图片附件 for (int i = 0; i < attachmentArray.Length; i++) { //attachmentinfoarray[i].Tid = topicid; //attachmentinfoarray[i].Pid = postid; Attachments.UpdateAttachment(attachmentArray[i]); aid[i] = attachmentArray[i].Aid; attType = attachmentArray[i].Filetype.ToLower().StartsWith("image") ? 2 : 1; } string tempMessage = Attachments.FilterLocalTags(aid, attachmentArray, postInfo.Message); if (tempMessage != postInfo.Message) { postInfo.Message = tempMessage; postInfo.Pid = postId; Posts.UpdatePost(postInfo); } if (newAttachCount > 0) UserCredits.UpdateUserExtCreditsByUploadAttachment(userId, newAttachCount); UpdateTopicAndPostAttachmentType(topicId, postId, attType); return true; }
/// <summary> /// 绑定附件数组中的参数,返回无效附件个数 /// </summary> /// <param name="attachmentinfo">附件类型</param> /// <param name="postid">帖子id</param> /// <param name="msg">原有提示信息</param> /// <param name="topicid">主题id</param> /// <param name="userid">用户id</param> /// <returns>无效附件个数</returns> public static int BindAttachment(AttachmentInfo[] attachmentinfo, int postid, StringBuilder msg, int topicid, int userid) { int acount = attachmentinfo.Length; // 附件查看权限 string[] readperm = String.IsNullOrEmpty(DNTRequest.GetString("readperm")) ? null : DNTRequest.GetString("readperm").Split(','); string[] attachdesc = DNTRequest.GetString("attachdesc") == null ? null : DNTRequest.GetString("attachdesc").Split(','); string[] localid = DNTRequest.GetString("localid") == null ? null : DNTRequest.GetString("localid").Split(','); //设置无效附件计数器,将在下面UserCreditsFactory.UpdateUserCreditsByUploadAttachment方法中减去该计数器的值 int errorAttachment = 0; int i_readperm = 0; for (int i = 0; i < acount; i++) { if (attachmentinfo[i] != null) { if (Utils.IsNumeric(localid[i+1])) attachmentinfo[i].Sys_index = Convert.ToInt32(localid[i+1]); attachmentinfo[i].Uid = userid; attachmentinfo[i].Tid = topicid; attachmentinfo[i].Pid = postid; attachmentinfo[i].Postdatetime = Utils.GetDateTime(); attachmentinfo[i].Readperm = 0; if (readperm != null) { i_readperm = Utils.StrToInt(readperm[i + 1], 0); //当为最大阅读仅限(255)时 i_readperm = i_readperm > 255 ? 255 : i_readperm; attachmentinfo[i].Readperm = i_readperm; } if (attachdesc != null && !attachdesc[i+1].Equals("")) { attachmentinfo[i].Description = Utils.HtmlEncode(attachdesc[i+1]); } if (!attachmentinfo[i].Sys_noupload.Equals("")) { msg.Append("<tr><td align=\"left\">"); msg.Append(attachmentinfo[i].Attachment); msg.Append("</td>"); msg.Append("<td align=\"left\">"); msg.Append(attachmentinfo[i].Sys_noupload); msg.Append("</td></tr>"); errorAttachment++; } } } return errorAttachment; }
/// <summary> /// 更新附件信息 /// </summary> /// <param name="attachmentInfo">附件对象</param> /// <returns>返回被更新的数量</returns> public static int UpdateAttachment(AttachmentInfo attachmentInfo) { if (attachmentInfo == null || attachmentInfo.Aid <= 0) return 0; return Discuz.Data.Attachments.UpdateAttachment(attachmentInfo); }
/// <summary> /// 产生附件 /// </summary> /// <param name="attachmentinfo">附件描述类实体</param> /// <returns>附件id</returns> public int CreateAttachment(AttachmentInfo attachmentinfo) { IDataParameter[] prams = { DbHelper.MakeInParam("@uid",(DbType)SqlDbType.Int,4,attachmentinfo.Uid), DbHelper.MakeInParam("@tid",(DbType)SqlDbType.Int,4,attachmentinfo.Tid), DbHelper.MakeInParam("@pid",(DbType)SqlDbType.Int,4,attachmentinfo.Pid), DbHelper.MakeInParam("@postdatetime",(DbType)SqlDbType.DateTime, 8, DateTime.Parse(attachmentinfo.Postdatetime)), DbHelper.MakeInParam("@readperm",(DbType)SqlDbType.Int,4,attachmentinfo.Readperm), DbHelper.MakeInParam("@filename",(DbType)SqlDbType.VarChar,100,attachmentinfo.Filename), DbHelper.MakeInParam("@description",(DbType)SqlDbType.VarChar,100,attachmentinfo.Description), DbHelper.MakeInParam("@filetype",(DbType)SqlDbType.VarChar,50,attachmentinfo.Filetype), DbHelper.MakeInParam("@filesize",(DbType)SqlDbType.Int,4,attachmentinfo.Filesize), DbHelper.MakeInParam("@attachment",(DbType)SqlDbType.VarChar,100,attachmentinfo.Attachment), DbHelper.MakeInParam("@downloads",(DbType)SqlDbType.Int,4,attachmentinfo.Downloads) }; return Utils.StrToInt(DbHelper.ExecuteScalar(CommandType.StoredProcedure, BaseConfigs.GetTablePrefix + "createattachment", prams), -1); }
/// <summary> #endregion 变量声明 protected override void ShowPage() { pagetitle = "附件下载"; // 如果当前用户非管理员并且论坛设定了禁止下载附件时间段,当前时间如果在其中的一个时间段内,则不允许用户下载附件 if (useradminid != 1 && usergroupinfo.Disableperiodctrl != 1) { string visittime = ""; if (Scoresets.BetweenTime(config.Attachbanperiods, out visittime)) { AddErrLine("在此时间段( " + visittime + " )内用户不可以下载附件"); return; } } // 获取附件ID attachmentid = DNTRequest.GetInt("attachmentid", -1); // 如果附件ID非数字 if(attachmentid == -1) { AddErrLine("无效的附件ID"); return; } if (DNTRequest.GetString("goodsattach") == "yes") { } else { // 获取该附件的信息 attachmentinfo = Attachments.GetAttachmentInfo(attachmentid); // 如果该附件不存在 if (attachmentinfo == null) { AddErrLine("不存在的附件ID"); return; } topicid = attachmentinfo.Tid; // 获取该主题的信息 topic = Topics.GetTopicInfo(topicid); // 如果该主题不存在 if (topic == null) { AddErrLine("不存在的主题ID"); return; } topictitle = topic.Title; forumid = topic.Fid; ForumInfo forum = Forums.GetForumInfo(forumid); forumname = forum.Name; pagetitle = Utils.RemoveHtml(forum.Name); forumnav = ForumUtils.UpdatePathListExtname(forum.Pathlist.Trim(), config.Extname); //添加判断特殊用户的代码 if (!Forums.AllowViewByUserID(forum.Permuserlist, userid)) { if (!Forums.AllowView(forum.Viewperm, usergroupid)) { AddErrLine("您没有浏览该版块的权限"); if (userid == -1) { needlogin = true; } return; } } //添加判断特殊用户的代码 if (!Forums.AllowGetAttachByUserID(forum.Permuserlist, userid)) { if (forum.Getattachperm == "" || forum.Getattachperm == null) { // 验证用户是否有下载附件的权限 if (usergroupinfo.Allowgetattach != 1) { AddErrLine("您当前的身份 \"" + usergroupinfo.Grouptitle + "\" 没有下载或查看附件的权限"); if (userid == -1) { needlogin = true; } return; } } else { if (!Forums.AllowGetAttach(forum.Getattachperm, usergroupid)) { AddErrLine("您没有在该版块下载附件的权限"); if (userid == -1) { needlogin = true; } return; } } } // 检查用户是否拥有足够的阅读权限 if ((attachmentinfo.Readperm > usergroupinfo.Readaccess) && (attachmentinfo.Uid != userid) && (!Moderators.IsModer(useradminid, userid, forumid))) { AddErrLine("您的阅读权限不够"); if (userid == -1) { needlogin = true; } return; } //如果图片是不直接显示(作为附件显示) 并且不是作者本人下载都会扣分 if (config.Showimages != 1 || !Utils.IsImgFilename(attachmentinfo.Filename.Trim()) && userid != attachmentinfo.Uid) { if (UserCredits.UpdateUserCreditsByDownloadAttachment(userid) == -1) { AddErrLine("您的金币不足"); return; } } if (attachmentinfo.Filename.IndexOf("http") < 0) { if (!System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + "upload/" + attachmentinfo.Filename)) { AddErrLine("该附件文件不存在或已被删除"); return; } } Attachments.UpdateAttachmentDownloads(attachmentid); if (attachmentinfo.Filename.IndexOf("http") < 0) { Utils.ResponseFile(AppDomain.CurrentDomain.BaseDirectory + "upload/" + attachmentinfo.Filename, System.IO.Path.GetFileName(attachmentinfo.Attachment), attachmentinfo.Filetype); //ResponseFile("/Forum/" + "upload/" + attachmentinfo.Filename.Trim(), attachmentinfo.Filetype); } else { //Utils.ResponseFile(attachmentinfo.Filename.Trim(), System.IO.Path.GetFileName(attachmentinfo.Filename).Trim(), attachmentinfo.Filetype); ResponseFile(attachmentinfo.Filename.Trim(), attachmentinfo.Filetype); } } }
/// <summary> /// 查看用户是否购买过指定附件 /// </summary> /// <param name="userid">购买用户id</param> /// <param name="aid">附件id</param> /// <returns></returns> public static bool HasBoughtAttach(int userid, int radminid, AttachmentInfo attachmentinfo) { //检查附件是否存在 return attachmentinfo.Attachprice > 0 && attachmentinfo.Uid != userid && radminid != 1 && !Data.AttachPaymentLogs.HasBoughtAttach(userid, attachmentinfo.Aid); }
/// <summary> /// 产生附件 /// </summary> /// <param name="attachmentinfo">附件描述类实体</param> /// <returns>附件id</returns> public int CreateAttachment(AttachmentInfo attachmentInfo) { DbParameter[] parms = { DbHelper.MakeInParam("@uid",(DbType)SqlDbType.Int,4,attachmentInfo.Uid), DbHelper.MakeInParam("@tid",(DbType)SqlDbType.Int,4,attachmentInfo.Tid), DbHelper.MakeInParam("@pid",(DbType)SqlDbType.Int,4,attachmentInfo.Pid), DbHelper.MakeInParam("@postdatetime",(DbType)SqlDbType.DateTime, 8, DateTime.Parse(attachmentInfo.Postdatetime)), DbHelper.MakeInParam("@readperm",(DbType)SqlDbType.Int,4,attachmentInfo.Readperm), DbHelper.MakeInParam("@filename",(DbType)SqlDbType.VarChar,100,attachmentInfo.Filename), DbHelper.MakeInParam("@description",(DbType)SqlDbType.VarChar,100,attachmentInfo.Description), DbHelper.MakeInParam("@filetype",(DbType)SqlDbType.VarChar,50,attachmentInfo.Filetype), DbHelper.MakeInParam("@filesize",(DbType)SqlDbType.Int,4,attachmentInfo.Filesize), DbHelper.MakeInParam("@attachment",(DbType)SqlDbType.VarChar,100,attachmentInfo.Attachment), DbHelper.MakeInParam("@downloads",(DbType)SqlDbType.Int,4,attachmentInfo.Downloads), DbHelper.MakeInParam("@extname",(DbType)SqlDbType.NVarChar,50,Utils.GetFileExtName(attachmentInfo.Attachment)), DbHelper.MakeInParam("@attachprice",(DbType)SqlDbType.Int,4,attachmentInfo.Attachprice), DbHelper.MakeInParam("@width",(DbType)SqlDbType.Int,4,attachmentInfo.Width), DbHelper.MakeInParam("@height",(DbType)SqlDbType.Int,4,attachmentInfo.Height), DbHelper.MakeInParam("@isimage",(DbType)SqlDbType.TinyInt,1,attachmentInfo.Isimage) }; return TypeConverter.ObjectToInt( DbHelper.ExecuteScalar(CommandType.StoredProcedure, string.Format("{0}createattachment", BaseConfigs.GetTablePrefix), parms), -1); }
/// <summary> /// 更新附件信息 /// </summary> /// <param name="attachmentInfo">附件对象</param> /// <returns>返回被更新的数量</returns> public static int UpdateAttachment(AttachmentInfo attachmentInfo) { if (appDBCache) IAttachmentService.UpdateAttachment(attachmentInfo); return DatabaseProvider.GetInstance().UpdateAttachment(attachmentInfo); }
/// <summary> /// 获取当前编辑帖子的附件id列表的附件信息列表 /// </summary> /// <param name="userid"></param> /// <param name="aidList"></param> /// <returns></returns> public static List<AttachmentInfo> GetEditPostAttachList(int userid, string aidList) { IDataReader reader = DatabaseProvider.GetInstance().GetEditPostAttachList(userid,aidList); List<AttachmentInfo> attachmentList = new List<AttachmentInfo>(); while (reader.Read()) { AttachmentInfo attach = new AttachmentInfo(); attach.Aid = TypeConverter.ObjectToInt(reader["aid"]); attach.Uid = TypeConverter.ObjectToInt(reader["uid"]); attach.Tid = TypeConverter.ObjectToInt(reader["tid"]); attach.Pid = TypeConverter.ObjectToInt(reader["pid"]); attach.Postdatetime = reader["postdatetime"].ToString(); attach.Readperm = TypeConverter.ObjectToInt(reader["readperm"]); attach.Filename = reader["filename"].ToString(); attach.Description = reader["description"].ToString().Trim(); attach.Filetype = reader["filetype"].ToString().Trim(); attach.Attachment = reader["attachment"].ToString().Trim(); attach.Filesize = TypeConverter.ObjectToInt(reader["filesize"]); attach.Downloads = TypeConverter.ObjectToInt(reader["downloads"]); attach.Attachprice = TypeConverter.ObjectToInt(reader["attachprice"], 0); attach.Height = TypeConverter.ObjectToInt(reader["height"]); attach.Width = TypeConverter.ObjectToInt(reader["width"], 0); attach.Isimage = TypeConverter.ObjectToInt(reader["isimage"], 0); attachmentList.Add(attach); } reader.Close(); return attachmentList; }
public string CreateAttachment(AttachmentInfo[] attachs, int usergroupid, int userid, string username) { return OnAttachCreated(attachs, usergroupid, userid, username); }
/// <summary> /// 保存上传的文件 /// </summary> /// <param name="forumid">版块id</param> /// <param name="MaxAllowFileCount">最大允许的上传文件个数</param> /// <param name="MaxSizePerDay">每天允许的附件大小总数</param> /// <param name="MaxFileSize">单个最大允许的文件字节数</param>/// /// <param name="TodayUploadedSize">今天已经上传的附件字节总数</param> /// <param name="AllowFileType">允许的文件类型, 以string[]形式提供</param> /// <param name="config">附件保存方式 0=按年/月/日存入不同目录 1=按年/月/日/论坛存入不同目录 2=按论坛存入不同目录 3=按文件类型存入不同目录</param> /// <param name="watermarkstatus">图片水印位置</param> /// <param name="filekey">File控件的Key(即Name属性)</param> /// <returns>文件信息结构</returns> public static AttachmentInfo[] SaveRequestFiles(int forumid, int MaxAllowFileCount, int MaxSizePerDay, int MaxFileSize, int TodayUploadedSize, string AllowFileType, int watermarkstatus, GeneralConfigInfo config, string filekey, bool isImage) { string[] tmp = Utils.SplitString(AllowFileType, "|"); string[] allowFileExtName = new string[tmp.Length]; int[] maxSize = new int[tmp.Length]; for (int i = 0; i < tmp.Length; i++) { allowFileExtName[i] = Utils.CutString(tmp[i], 0, tmp[i].LastIndexOf(",")); maxSize[i] = Utils.StrToInt(Utils.CutString(tmp[i], tmp[i].LastIndexOf(",") + 1), 0); } int saveFileCount = 0; int fCount = HttpContext.Current.Request.Files.Count; for (int i = 0; i < fCount; i++) { if (!HttpContext.Current.Request.Files[i].FileName.Equals("") && HttpContext.Current.Request.Files.AllKeys[i].Equals(filekey)) { saveFileCount++; } } AttachmentInfo[] attachmentInfo = saveFileCount > 0 ? new AttachmentInfo[saveFileCount] : null; if (saveFileCount > MaxAllowFileCount) return attachmentInfo; saveFileCount = 0; Random random = new Random(unchecked((int)DateTime.Now.Ticks)); for (int i = 0; i < fCount; i++) { if (!HttpContext.Current.Request.Files[i].FileName.Equals("") && HttpContext.Current.Request.Files.AllKeys[i].Equals(filekey)) { string fileName = Path.GetFileName(HttpContext.Current.Request.Files[i].FileName); string fileExtName = Utils.CutString(fileName, fileName.LastIndexOf(".") + 1).ToLower(); string fileType = HttpContext.Current.Request.Files[i].ContentType.ToLower(); int fileSize = HttpContext.Current.Request.Files[i].ContentLength; string newFileName = ""; //flash批量上传时无法获取contenttype if (fileType == "application/octet-stream") fileType = GetContentType(fileExtName); attachmentInfo[saveFileCount] = new AttachmentInfo(); attachmentInfo[saveFileCount].Sys_noupload = ""; // 判断 文件扩展名/文件大小/文件类型 是否符合要求 if (!(Utils.IsImgFilename(fileName) && !fileType.StartsWith("image")) && ValidateImage(fileType, HttpContext.Current.Request.Files[i].InputStream)) { int extnameid = Utils.GetInArrayID(fileExtName, allowFileExtName); if (extnameid >= 0 && (fileSize <= maxSize[extnameid]) && (MaxFileSize >= fileSize /*|| MaxAllSize == 0*/) && (MaxSizePerDay - TodayUploadedSize >= fileSize)) { TodayUploadedSize = TodayUploadedSize + fileSize; string UploadDir = Utils.GetMapPath(BaseConfigs.GetForumPath + "upload/"); string saveDir = GetAttachmentPath(forumid, config, fileExtName); newFileName = string.Format("{0}{1}{2}.{3}", (Environment.TickCount & int.MaxValue).ToString(), i.ToString(), random.Next(1000, 9999).ToString(), fileExtName); //(Environment.TickCount & int.MaxValue).ToString() + i.ToString() + random.Next(1000, 9999).ToString() + "." + fileextname; //临时文件名称变量. 用于当启动远程附件之后,先上传到本地临时文件夹的路径信息 string tempFileName = ""; //当支持FTP上传附件且不保留本地附件时 if (FTPs.GetForumAttachInfo.Allowupload == 1 && FTPs.GetForumAttachInfo.Reservelocalattach == 0) { // 如果指定目录不存在则建立临时路径 if (!Directory.Exists(UploadDir + "temp\\")) Utils.CreateDir(UploadDir + "temp\\"); tempFileName = "temp\\" + newFileName; } // 如果指定目录不存在则建立 else if (!Directory.Exists(UploadDir + saveDir)) Utils.CreateDir(UploadDir + saveDir); newFileName = saveDir + newFileName; try { // 如果是bmp jpg png图片类型 if ((fileExtName == "bmp" || fileExtName == "jpg" || fileExtName == "jpeg" || fileExtName == "png") && fileType.StartsWith("image")) { Image img = Image.FromStream(HttpContext.Current.Request.Files[i].InputStream); if (config.Attachimgmaxwidth > 0 && img.Width > config.Attachimgmaxwidth) attachmentInfo[saveFileCount].Sys_noupload = "图片宽度为" + img.Width + ", 系统允许的最大宽度为" + config.Attachimgmaxwidth; if (config.Attachimgmaxheight > 0 && img.Height > config.Attachimgmaxheight) attachmentInfo[saveFileCount].Sys_noupload = "图片高度为" + img.Width + ", 系统允许的最大高度为" + config.Attachimgmaxheight; attachmentInfo[saveFileCount].Width = img.Width; attachmentInfo[saveFileCount].Height = img.Height; if (attachmentInfo[saveFileCount].Sys_noupload == "") { if (watermarkstatus == 0) { //当支持FTP上传附件且不保留本地附件模式时,则先上传到临时目录下 if (FTPs.GetForumAttachInfo.Allowupload == 1 && FTPs.GetForumAttachInfo.Reservelocalattach == 0) HttpContext.Current.Request.Files[i].SaveAs(UploadDir + tempFileName); else HttpContext.Current.Request.Files[i].SaveAs(UploadDir + newFileName); attachmentInfo[saveFileCount].Filesize = fileSize; } else { if (config.Watermarktype == 1 && File.Exists(Utils.GetMapPath(BaseConfigs.GetForumPath + "watermark/" + config.Watermarkpic))) { //当支持FTP上传附件且不保留本地附件模式时,则先上传到临时目录下 if (FTPs.GetForumAttachInfo.Allowupload == 1 && FTPs.GetForumAttachInfo.Reservelocalattach == 0) AddImageSignPic(img, UploadDir + tempFileName, Utils.GetMapPath(BaseConfigs.GetForumPath + "watermark/" + config.Watermarkpic), config.Watermarkstatus, config.Attachimgquality, config.Watermarktransparency); else AddImageSignPic(img, UploadDir + newFileName, Utils.GetMapPath(BaseConfigs.GetForumPath + "watermark/" + config.Watermarkpic), config.Watermarkstatus, config.Attachimgquality, config.Watermarktransparency); } else { string watermarkText; watermarkText = config.Watermarktext.Replace("{1}", config.Forumtitle); watermarkText = watermarkText.Replace("{2}", "http://" + DNTRequest.GetCurrentFullHost() + "/"); watermarkText = watermarkText.Replace("{3}", Utils.GetDate()); watermarkText = watermarkText.Replace("{4}", Utils.GetTime()); //当支持FTP上传附件且不保留本地附件模式时,则先上传到临时目录下 if (FTPs.GetForumAttachInfo.Allowupload == 1 && FTPs.GetForumAttachInfo.Reservelocalattach == 0) AddImageSignText(img, UploadDir + tempFileName, watermarkText, config.Watermarkstatus, config.Attachimgquality, config.Watermarkfontname, config.Watermarkfontsize); else AddImageSignText(img, UploadDir + newFileName, watermarkText, config.Watermarkstatus, config.Attachimgquality, config.Watermarkfontname, config.Watermarkfontsize); } //当支持FTP上传附件且不保留本地附件模式时,则读取临时目录下的文件信息 if (FTPs.GetForumAttachInfo.Allowupload == 1 && FTPs.GetForumAttachInfo.Reservelocalattach == 0) attachmentInfo[saveFileCount].Filesize = new FileInfo(UploadDir + tempFileName).Length; else attachmentInfo[saveFileCount].Filesize = new FileInfo(UploadDir + newFileName).Length; } } } else { attachmentInfo[saveFileCount].Filesize = fileSize; //当支持FTP上传附件且不保留本地附件模式时,则先上传到临时目录下 if (FTPs.GetForumAttachInfo.Allowupload == 1 && FTPs.GetForumAttachInfo.Reservelocalattach == 0) HttpContext.Current.Request.Files[i].SaveAs(UploadDir + tempFileName); else HttpContext.Current.Request.Files[i].SaveAs(UploadDir + newFileName); } } catch { //当上传目录和临时文件夹都没有上传的文件时 if (!(Utils.FileExists(UploadDir + tempFileName)) && (!(Utils.FileExists(UploadDir + newFileName)))) { attachmentInfo[saveFileCount].Filesize = fileSize; //当支持FTP上传附件且不保留本地附件模式时,则先上传到临时目录下 if (FTPs.GetForumAttachInfo.Allowupload == 1 && FTPs.GetForumAttachInfo.Reservelocalattach == 0) HttpContext.Current.Request.Files[i].SaveAs(UploadDir + tempFileName); else HttpContext.Current.Request.Files[i].SaveAs(UploadDir + newFileName); } } try { //加载文件预览类指定方法 IPreview preview = PreviewProvider.GetInstance(fileExtName.Trim()); if (preview != null) { preview.UseFTP = (FTPs.GetForumAttachInfo.Allowupload == 1) ? true : false; //当支持FTP上传附件且不保留本地附件模式时 if (FTPs.GetForumAttachInfo.Allowupload == 1 && FTPs.GetForumAttachInfo.Reservelocalattach == 0) preview.OnSaved(UploadDir + tempFileName); else preview.OnSaved(UploadDir + newFileName); } } catch { } //当支持FTP上传附件时,使用FTP上传远程附件 if (FTPs.GetForumAttachInfo.Allowupload == 1) { FTPs ftps = new FTPs(); //当不保留本地附件模式时,在上传完成之后删除本地tempfilename文件 if (FTPs.GetForumAttachInfo.Reservelocalattach == 0) ftps.UpLoadFile(newFileName.Substring(0, newFileName.LastIndexOf("\\")), UploadDir + tempFileName, FTPs.FTPUploadEnum.ForumAttach); else ftps.UpLoadFile(newFileName.Substring(0, newFileName.LastIndexOf("\\")), UploadDir + newFileName, FTPs.FTPUploadEnum.ForumAttach); } if (EntLibConfigs.GetConfig() != null && EntLibConfigs.GetConfig().Cacheattachfiles.Enable && EntLibConfigs.GetConfig().Cacheattachfiles.Attachpostid > 0) Discuz.Cache.Data.DBCacheService.GetAttachFilesService().UploadFile(UploadDir, newFileName); } else { if (extnameid < 0) attachmentInfo[saveFileCount].Sys_noupload = "文件格式无效"; else if (MaxSizePerDay - TodayUploadedSize < fileSize) attachmentInfo[saveFileCount].Sys_noupload = "文件大于今天允许上传的字节数"; else if (fileSize > maxSize[extnameid]) attachmentInfo[saveFileCount].Sys_noupload = "文件大于该类型附件允许的字节数"; else attachmentInfo[saveFileCount].Sys_noupload = "文件大于单个文件允许上传的字节数"; } } else { attachmentInfo[saveFileCount].Sys_noupload = "文件格式无效"; } //当支持FTP上传附件时 if (FTPs.GetForumAttachInfo.Allowupload == 1) attachmentInfo[saveFileCount].Filename = FTPs.GetForumAttachInfo.Remoteurl + "/" + newFileName.Replace("\\", "/"); else attachmentInfo[saveFileCount].Filename = newFileName; attachmentInfo[saveFileCount].Description = ""; attachmentInfo[saveFileCount].Filetype = fileType; attachmentInfo[saveFileCount].Attachment = fileName; attachmentInfo[saveFileCount].Downloads = 0; attachmentInfo[saveFileCount].Postdatetime = DateTime.Now.ToString(); attachmentInfo[saveFileCount].Sys_index = i; attachmentInfo[saveFileCount].Isimage = isImage ? 1 : 0; saveFileCount++; } } return attachmentInfo; }
public void CreateTopic(TopicInfo topic, PostInfo post, AttachmentInfo[] attachs) { OnTopicCreated(topic, post, attachs); }
protected virtual string OnAttachCreated(AttachmentInfo[] attachs, int usergroupid, int userid, string username) { return ""; }
protected virtual void OnTopicCreated(TopicInfo topic, PostInfo post, AttachmentInfo[] attachs) { }
protected override void ShowPage() { pagetitle = "附件下载"; if (attachmentid == -1) { AddErrLine("无效的附件ID"); return; } // 如果当前用户非管理员并且论坛设定了禁止下载附件时间段,当前时间如果在其中的一个时间段内,则不允许用户下载附件 if (useradminid != 1 && usergroupinfo.Disableperiodctrl != 1) { string visitTime = ""; if (Scoresets.BetweenTime(config.Attachbanperiods, out visitTime)) { AddErrLine("在此时间段( " + visitTime + " )内用户不可以下载附件"); return; } } if (DNTRequest.GetString("goodsattach").ToLower() == "yes") GetGoodsAttachInfo(attachmentid); else { // 获取该附件的信息 attachmentinfo = Attachments.GetAttachmentInfo(attachmentid); if (attachmentinfo == null) { AddErrLine("不存在的附件ID"); return; } //当前用户已上传但是还没有绑定到帖子的附件需要特殊处理,直接输出图片 if (userid > 0 && userid == attachmentinfo.Uid && attachmentinfo.Tid == 0 && attachmentinfo.Filetype.StartsWith("image/")) { HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Redirect(attachmentinfo.Filename.IndexOf("http") < 0 ? BaseConfigs.GetForumPath + "upload/" + attachmentinfo.Filename.Trim() : attachmentinfo.Filename.Trim()); HttpContext.Current.Response.End(); return; } // 获取该主题的信息 topic = Topics.GetTopicInfo(attachmentinfo.Tid); if (topic == null) { AddErrLine("不存在的主题ID"); return; } ForumInfo forum = Forums.GetForumInfo(topic.Fid); pagetitle = Utils.RemoveHtml(forum.Name); if (!UserAuthority.VisitAuthority(forum, usergroupinfo, userid, ref msg)) { AddErrLine(msg); if (userid == -1) needlogin = true; return; } //添加判断特殊用户的代码 if (!UserAuthority.CheckUsertAttachAuthority(forum, usergroupinfo, userid, ref msg)) { AddErrLine(msg); if (userid == -1) needlogin = true; return; } // 检查用户是否拥有足够的阅读权限 if ((attachmentinfo.Readperm > usergroupinfo.Readaccess) && (attachmentinfo.Uid != userid) && (!Moderators.IsModer(useradminid, userid, forum.Fid))) { AddErrLine("您的阅读权限不够"); if (userid == -1) needlogin = true; return; } //检查附件是否存在 if (attachmentinfo.Filename.IndexOf("http") < 0 && !File.Exists(Utils.GetMapPath(string.Format(@"{0}upload/{1}", BaseConfigs.GetForumPath, attachmentinfo.Filename)))) { AddErrLine("该附件文件不存在或已被删除"); return; } //如果图片是不直接显示(作为附件显示) 并且不是作者本人下载都会扣分,并判断是否已经下载过,如果下载过则不再扣积分 //if ((config.Showimages != 1 || !Utils.IsImgFilename(attachmentinfo.Filename.Trim()) && // userid != attachmentinfo.Uid) && Utils.StrIsNullOrEmpty(Utils.GetCookie("dnt_attachment_" + attachmentid))) if ((!Utils.IsImgFilename(attachmentinfo.Filename.Trim()) || config.Showimages != 1) && (userid != attachmentinfo.Uid && Utils.StrIsNullOrEmpty(Utils.GetCookie("dnt_attachment_" + attachmentid)))) { if (Scoresets.IsSetDownLoadAttachScore() && UserCredits.UpdateUserExtCreditsByDownloadAttachment(userid, 1) == -1) { string addExtCreditsTip = ""; if (EPayments.IsOpenEPayments()) addExtCreditsTip = "<br/><span><a href=\"usercpcreditspay.aspx\">点击充值积分</a></span>"; AddErrLine("您的积分不足" + addExtCreditsTip); return; } //设置该附件已经下载的cookie Utils.WriteCookie("dnt_attachment_" + attachmentid, "true", 5); } //检查附件是否存在 if (AttachPaymentLogs.HasBoughtAttach(userid, usergroupinfo.Radminid, attachmentinfo)) { AddErrLine("该附件为交易附件, 请先行购买!"); return; } Attachments.UpdateAttachmentDownloads(attachmentid); if (attachmentinfo.Filename.IndexOf("http") < 0) Utils.ResponseFile(Utils.GetMapPath(BaseConfigs.GetForumPath + @"upload/" + attachmentinfo.Filename), Path.GetFileName(attachmentinfo.Attachment), attachmentinfo.Filetype); else { try //添加try语法, 以防止在并发访问情况下, 服务器端远程链接被关闭后出现应用程序 '警告'(事件查看器) { HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Redirect(attachmentinfo.Filename.Trim()); HttpContext.Current.Response.End(); } catch{} } } }
/// <summary> /// �����ϴ����ļ� /// </summary> /// <param name="forumid">���id</param> /// <param name="MaxAllowFileCount">���������ϴ��ļ�����</param> /// <param name="MaxSizePerDay">ÿ������ĸ�����С����</param> /// <param name="MaxFileSize">�������������ļ��ֽ���</param>/// /// <param name="TodayUploadedSize">�����Ѿ��ϴ��ĸ����ֽ�����</param> /// <param name="AllowFileType">������ļ�����, ��string[]��ʽ�ṩ</param> /// <param name="config">�������淽ʽ 0=����/��/�մ��벻ͬĿ¼ 1=����/��/��/��̳���벻ͬĿ¼ 2=����̳���벻ͬĿ¼ 3=���ļ����ʹ��벻ͬĿ¼</param> /// <param name="watermarkstatus">ͼƬˮӡλ��</param> /// <param name="filekey">File�ؼ���Key(��Name����)</param> /// <returns>�ļ���Ϣ�ṹ</returns> public static AttachmentInfo[] SaveRequestFiles(int forumid, int MaxAllowFileCount, int MaxSizePerDay, int MaxFileSize, int TodayUploadedSize, string AllowFileType, int watermarkstatus, GeneralConfigInfo config, string filekey,bool isImage) { string[] tmp = Utils.SplitString(AllowFileType, "|"); string[] allowFileExtName = new string[tmp.Length]; int[] maxSize = new int[tmp.Length]; for (int i = 0; i < tmp.Length; i++) { allowFileExtName[i] = Utils.CutString(tmp[i], 0, tmp[i].LastIndexOf(",")); maxSize[i] = Utils.StrToInt(Utils.CutString(tmp[i], tmp[i].LastIndexOf(",") + 1), 0); } int saveFileCount = 0; int fCount = HttpContext.Current.Request.Files.Count; for (int i = 0; i < fCount; i++) { if (!HttpContext.Current.Request.Files[i].FileName.Equals("") && HttpContext.Current.Request.Files.AllKeys[i].Equals(filekey)) { saveFileCount++; } } AttachmentInfo[] attachmentInfo = saveFileCount > 0 ? new AttachmentInfo[saveFileCount] : null; if (saveFileCount > MaxAllowFileCount) return attachmentInfo; saveFileCount = 0; Random random = new Random(unchecked((int)DateTime.Now.Ticks)); for (int i = 0; i < fCount; i++) { if (!HttpContext.Current.Request.Files[i].FileName.Equals("") && HttpContext.Current.Request.Files.AllKeys[i].Equals(filekey)) { string fileName = Path.GetFileName(HttpContext.Current.Request.Files[i].FileName); string fileExtName = Utils.CutString(fileName, fileName.LastIndexOf(".") + 1).ToLower(); string fileType = HttpContext.Current.Request.Files[i].ContentType.ToLower(); int fileSize = HttpContext.Current.Request.Files[i].ContentLength; string newFileName = ""; //flash�����ϴ�ʱ����ȡcontenttype if (fileType == "application/octet-stream") fileType = GetContentType(fileExtName); attachmentInfo[saveFileCount] = new AttachmentInfo(); attachmentInfo[saveFileCount].Sys_noupload = ""; // �ж� �ļ���չ��/�ļ���С/�ļ����� �Ƿ����Ҫ�� if (!(Utils.IsImgFilename(fileName) && !fileType.StartsWith("image"))) { int extnameid = Utils.GetInArrayID(fileExtName, allowFileExtName); if (extnameid >= 0 && (fileSize <= maxSize[extnameid]) && (MaxFileSize >= fileSize /*|| MaxAllSize == 0*/) && (MaxSizePerDay - TodayUploadedSize >= fileSize)) { TodayUploadedSize = TodayUploadedSize + fileSize; string UploadDir = Utils.GetMapPath(BaseConfigs.GetForumPath + "upload/"); string saveDir = GetAttachmentPath(forumid, config, fileExtName); newFileName = string.Format("{0}{1}{2}.{3}", (Environment.TickCount & int.MaxValue).ToString(), i.ToString(), random.Next(1000, 9999).ToString(), fileExtName); //(Environment.TickCount & int.MaxValue).ToString() + i.ToString() + random.Next(1000, 9999).ToString() + "." + fileextname; //��ʱ�ļ����Ʊ���. ���ڵ����Զ�̸���֮��,���ϴ���������ʱ�ļ��е�·����Ϣ string tempFileName = ""; //��֧��FTP�ϴ������Ҳ�������ظ���ʱ if (FTPs.GetForumAttachInfo.Allowupload == 1 && FTPs.GetForumAttachInfo.Reservelocalattach == 0) { // ���ָ��Ŀ¼������������ʱ·�� if (!Directory.Exists(UploadDir + "temp\\")) Utils.CreateDir(UploadDir + "temp\\"); tempFileName = "temp\\" + newFileName; } // ���ָ��Ŀ¼���������� else if (!Directory.Exists(UploadDir + saveDir)) Utils.CreateDir(UploadDir + saveDir); newFileName = saveDir + newFileName; try { // �����bmp jpg pngͼƬ���� if ((fileExtName == "bmp" || fileExtName == "jpg" || fileExtName == "jpeg" || fileExtName == "png") && fileType.StartsWith("image")) { Image img = Image.FromStream(HttpContext.Current.Request.Files[i].InputStream); if (config.Attachimgmaxwidth > 0 && img.Width > config.Attachimgmaxwidth) attachmentInfo[saveFileCount].Sys_noupload = "ͼƬ���Ϊ" + img.Width + ", ϵͳ����������Ϊ" + config.Attachimgmaxwidth; if (config.Attachimgmaxheight > 0 && img.Height > config.Attachimgmaxheight) attachmentInfo[saveFileCount].Sys_noupload = "ͼƬ�߶�Ϊ" + img.Width + ", ϵͳ��������߶�Ϊ" + config.Attachimgmaxheight; attachmentInfo[saveFileCount].Width = img.Width; attachmentInfo[saveFileCount].Height = img.Height; if (attachmentInfo[saveFileCount].Sys_noupload == "") { if (watermarkstatus == 0) { //��֧��FTP�ϴ������Ҳ�������ظ���ģʽʱ,�����ϴ�����ʱĿ¼�� if (FTPs.GetForumAttachInfo.Allowupload == 1 && FTPs.GetForumAttachInfo.Reservelocalattach == 0) HttpContext.Current.Request.Files[i].SaveAs(UploadDir + tempFileName); else HttpContext.Current.Request.Files[i].SaveAs(UploadDir + newFileName); attachmentInfo[saveFileCount].Filesize = fileSize; } else { if (config.Watermarktype == 1 && File.Exists(Utils.GetMapPath(BaseConfigs.GetForumPath + "watermark/" + config.Watermarkpic))) { //��֧��FTP�ϴ������Ҳ�������ظ���ģʽʱ,�����ϴ�����ʱĿ¼�� if (FTPs.GetForumAttachInfo.Allowupload == 1 && FTPs.GetForumAttachInfo.Reservelocalattach == 0) AddImageSignPic(img, UploadDir + tempFileName, Utils.GetMapPath(BaseConfigs.GetForumPath + "watermark/" + config.Watermarkpic), config.Watermarkstatus, config.Attachimgquality, config.Watermarktransparency); else AddImageSignPic(img, UploadDir + newFileName, Utils.GetMapPath(BaseConfigs.GetForumPath + "watermark/" + config.Watermarkpic), config.Watermarkstatus, config.Attachimgquality, config.Watermarktransparency); } else { string watermarkText; watermarkText = config.Watermarktext.Replace("{1}", config.Forumtitle); watermarkText = watermarkText.Replace("{2}", "http://" + DNTRequest.GetCurrentFullHost() + "/"); watermarkText = watermarkText.Replace("{3}", Utils.GetDate()); watermarkText = watermarkText.Replace("{4}", Utils.GetTime()); //��֧��FTP�ϴ������Ҳ�������ظ���ģʽʱ,�����ϴ�����ʱĿ¼�� if (FTPs.GetForumAttachInfo.Allowupload == 1 && FTPs.GetForumAttachInfo.Reservelocalattach == 0) AddImageSignText(img, UploadDir + tempFileName, watermarkText, config.Watermarkstatus, config.Attachimgquality, config.Watermarkfontname, config.Watermarkfontsize); else AddImageSignText(img, UploadDir + newFileName, watermarkText, config.Watermarkstatus, config.Attachimgquality, config.Watermarkfontname, config.Watermarkfontsize); } //��֧��FTP�ϴ������Ҳ�������ظ���ģʽʱ,���ȡ��ʱĿ¼�µ��ļ���Ϣ if (FTPs.GetForumAttachInfo.Allowupload == 1 && FTPs.GetForumAttachInfo.Reservelocalattach == 0) attachmentInfo[saveFileCount].Filesize = new FileInfo(UploadDir + tempFileName).Length; else attachmentInfo[saveFileCount].Filesize = new FileInfo(UploadDir + newFileName).Length; } } } else { attachmentInfo[saveFileCount].Filesize = fileSize; //��֧��FTP�ϴ������Ҳ�������ظ���ģʽʱ,�����ϴ�����ʱĿ¼�� if (FTPs.GetForumAttachInfo.Allowupload == 1 && FTPs.GetForumAttachInfo.Reservelocalattach == 0) HttpContext.Current.Request.Files[i].SaveAs(UploadDir + tempFileName); else HttpContext.Current.Request.Files[i].SaveAs(UploadDir + newFileName); } } catch { //���ϴ�Ŀ¼����ʱ�ļ��ж�û���ϴ����ļ�ʱ if (!(Utils.FileExists(UploadDir + tempFileName)) && (!(Utils.FileExists(UploadDir + newFileName)))) { attachmentInfo[saveFileCount].Filesize = fileSize; //��֧��FTP�ϴ������Ҳ�������ظ���ģʽʱ,�����ϴ�����ʱĿ¼�� if (FTPs.GetForumAttachInfo.Allowupload == 1 && FTPs.GetForumAttachInfo.Reservelocalattach == 0) HttpContext.Current.Request.Files[i].SaveAs(UploadDir + tempFileName); else HttpContext.Current.Request.Files[i].SaveAs(UploadDir + newFileName); } } try { //�����ļ�Ԥ����ָ������ IPreview preview = PreviewProvider.GetInstance(fileExtName.Trim()); if (preview != null) { preview.UseFTP = (FTPs.GetForumAttachInfo.Allowupload == 1) ? true : false; //��֧��FTP�ϴ������Ҳ�������ظ���ģʽʱ if (FTPs.GetForumAttachInfo.Allowupload == 1 && FTPs.GetForumAttachInfo.Reservelocalattach == 0) preview.OnSaved(UploadDir + tempFileName); else preview.OnSaved(UploadDir + newFileName); } } catch { } //��֧��FTP�ϴ�����ʱ,ʹ��FTP�ϴ�Զ�̸��� if (FTPs.GetForumAttachInfo.Allowupload == 1) { FTPs ftps = new FTPs(); //����������ظ���ģʽʱ,���ϴ����֮��ɾ������tempfilename�ļ� if (FTPs.GetForumAttachInfo.Reservelocalattach == 0) ftps.UpLoadFile(newFileName.Substring(0, newFileName.LastIndexOf("\\")), UploadDir + tempFileName, FTPs.FTPUploadEnum.ForumAttach); else ftps.UpLoadFile(newFileName.Substring(0, newFileName.LastIndexOf("\\")), UploadDir + newFileName, FTPs.FTPUploadEnum.ForumAttach); } if (EntLibConfigs.GetConfig() != null && EntLibConfigs.GetConfig().Cacheattachfiles.Enable && EntLibConfigs.GetConfig().Cacheattachfiles.Attachpostid > 0) Discuz.Cache.Data.DBCacheService.GetAttachFilesService().UploadFile(UploadDir, newFileName); } else { if (extnameid < 0) attachmentInfo[saveFileCount].Sys_noupload = "�ļ���ʽ��Ч"; else if (MaxSizePerDay - TodayUploadedSize < fileSize) attachmentInfo[saveFileCount].Sys_noupload = "�ļ����ڽ��������ϴ����ֽ���"; else if (fileSize > maxSize[extnameid]) attachmentInfo[saveFileCount].Sys_noupload = "�ļ����ڸ�������������ֽ���"; else attachmentInfo[saveFileCount].Sys_noupload = "�ļ����ڵ����ļ������ϴ����ֽ���"; } } else { attachmentInfo[saveFileCount].Sys_noupload = "�ļ���ʽ��Ч"; } //��֧��FTP�ϴ�����ʱ if (FTPs.GetForumAttachInfo.Allowupload == 1) attachmentInfo[saveFileCount].Filename = FTPs.GetForumAttachInfo.Remoteurl + "/" + newFileName.Replace("\\", "/"); else attachmentInfo[saveFileCount].Filename = newFileName; attachmentInfo[saveFileCount].Description = ""; attachmentInfo[saveFileCount].Filetype = fileType; attachmentInfo[saveFileCount].Attachment = fileName; attachmentInfo[saveFileCount].Downloads = 0; attachmentInfo[saveFileCount].Postdatetime = DateTime.Now.ToString(); attachmentInfo[saveFileCount].Sys_index = i; attachmentInfo[saveFileCount].Isimage = isImage ? 1 : 0; saveFileCount++; } } return attachmentInfo; }
/// <summary> /// 添加附件 /// </summary> /// <param name="savedfileName">上传之后保存的文件名称</param> /// <param name="fileName">文件名称</param> /// <param name="creinfo">认证信息</param> /// <returns>返回当前插入的附件id</returns> private int AddAttachment(string savedFileName, string fileName, CredentialInfo creinfo) { string UploadDir = GetUploadFolder(savedFileName, creinfo.ForumID.ToString()); AttachmentInfo attachmentinfo = new AttachmentInfo(); string fileextname = Utils.CutString(savedFileName, savedFileName.LastIndexOf(".") + 1).ToLower(); Random random = new Random(unchecked((int)DateTime.Now.Ticks)); string newfilename = string.Format("{0}{1}{2}.{3}", (Environment.TickCount & int.MaxValue).ToString(), random.Next(1000, 99999), random.Next(1000, 99999), fileextname); try { // 如果是bmp jpg png图片类型 if ((fileextname == "bmp" || fileextname == "jpg" || fileextname == "jpeg" || fileextname == "png")) { if (Discuz.Common.Utils.FileExists(UploadDir + savedFileName)) { System.Drawing.Image img = System.Drawing.Image.FromFile(UploadDir + savedFileName); //System.IO.File.Copy(UploadDir + savedFileName, UploadDir + newfilename, true); if (config.Attachimgmaxwidth > 0 && img.Width > config.Attachimgmaxwidth) attachmentinfo.Sys_noupload = "图片宽度为" + img.Width.ToString() + ", 系统允许的最大宽度为" + config.Attachimgmaxwidth.ToString(); if (config.Attachimgmaxheight > 0 && img.Height > config.Attachimgmaxheight) attachmentinfo.Sys_noupload = "图片高度为" + img.Width.ToString() + ", 系统允许的最大高度为" + config.Attachimgmaxheight.ToString(); attachmentinfo.Width = img.Width; attachmentinfo.Height = img.Height; if (config.Watermarkstatus == 0) { img.Dispose(); File.Move(UploadDir + savedFileName, UploadDir + newfilename); } else { if (config.Watermarktype == 1 && File.Exists(Utils.GetMapPath(BaseConfigs.GetForumPath + "watermark/" + config.Watermarkpic))) Discuz.Forum.ForumUtils.AddImageSignPic(img, UploadDir + newfilename, Utils.GetMapPath(BaseConfigs.GetForumPath + "watermark/" + config.Watermarkpic), config.Watermarkstatus, config.Attachimgquality, config.Watermarktransparency); else { string watermarkText; watermarkText = config.Watermarktext.Replace("{1}", config.Forumtitle); watermarkText = watermarkText.Replace("{2}", "http://" + DNTRequest.GetCurrentFullHost() + "/"); watermarkText = watermarkText.Replace("{3}", Utils.GetDate()); watermarkText = watermarkText.Replace("{4}", Utils.GetTime()); Discuz.Forum.ForumUtils.AddImageSignText(img, UploadDir + newfilename, watermarkText, config.Watermarkstatus, config.Attachimgquality, config.Watermarkfontname, config.Watermarkfontsize); } System.IO.File.Delete(UploadDir + savedFileName); } // 获得文件长度 attachmentinfo.Filesize = new FileInfo(UploadDir + newfilename).Length; } } else { System.IO.File.Move(UploadDir + savedFileName, UploadDir + newfilename); attachmentinfo.Filesize = new FileInfo(UploadDir + newfilename).Length; } } catch {} if (Discuz.Common.Utils.FileExists(UploadDir + savedFileName)) { attachmentinfo.Filesize = new FileInfo(UploadDir + savedFileName).Length; attachmentinfo.Filename = GetDirInfo(savedFileName, creinfo.ForumID.ToString()) + savedFileName; } if (Discuz.Common.Utils.FileExists(UploadDir + newfilename)) { attachmentinfo.Filesize = new FileInfo(UploadDir + newfilename).Length; attachmentinfo.Filename = GetDirInfo(newfilename, creinfo.ForumID.ToString()) + newfilename; } //当支持FTP上传附件时 if (FTPs.GetForumAttachInfo != null && FTPs.GetForumAttachInfo.Allowupload == 1) attachmentinfo.Filename = FTPs.GetForumAttachInfo.Remoteurl + "/" + newfilename.Replace("\\", "/"); attachmentinfo.Uid = creinfo.UserID; attachmentinfo.Description = fileextname; attachmentinfo.Filetype = GetContentType(fileextname); attachmentinfo.Attachment = fileName; attachmentinfo.Downloads = 0; attachmentinfo.Postdatetime = DateTime.Now.ToString(); attachmentinfo.Sys_index = 0; //return Discuz.Data.DatabaseProvider.GetInstance().CreateAttachment(attachmentinfo); return Discuz.Data.Attachments.CreateAttachments(attachmentinfo); }
private static AttachmentInfo LoadAttachmentInfo(IDataReader reader) { AttachmentInfo attach = new AttachmentInfo(); attach.Aid = TypeConverter.ObjectToInt(reader["aid"]); attach.Uid = TypeConverter.ObjectToInt(reader["uid"]); attach.Tid = TypeConverter.ObjectToInt(reader["tid"]); attach.Pid = TypeConverter.ObjectToInt(reader["pid"]); attach.Postdatetime = reader["postdatetime"].ToString(); attach.Readperm = TypeConverter.ObjectToInt(reader["readperm"]); attach.Filename = reader["filename"].ToString(); attach.Description = reader["description"].ToString().Trim(); attach.Filetype = reader["filetype"].ToString().Trim(); attach.Attachment = reader["attachment"].ToString().Trim(); attach.Filesize = TypeConverter.ObjectToInt(reader["filesize"]); attach.Downloads = TypeConverter.ObjectToInt(reader["downloads"]); attach.Attachprice = TypeConverter.ObjectToInt(reader["attachprice"], 0); attach.Height = TypeConverter.ObjectToInt(reader["height"]); attach.Width = TypeConverter.ObjectToInt(reader["width"], 0); attach.Isimage = TypeConverter.ObjectToInt(reader["isimage"], 0); return attach; }
/// <summary> /// 得到空间格式的帖子内容 /// </summary> /// <param name="postinfo">帖子描述</param> /// <param name="attArray">附件集合</param> /// <returns>空间格式</returns> public static string GetPostMessageHTML(PostInfo postInfo, AttachmentInfo[] attachmentArray) { string message = ""; PostpramsInfo postpramsInfo = new PostpramsInfo(); //处理帖子内容 postpramsInfo.Smileyoff = postInfo.Smileyoff; postpramsInfo.Bbcodeoff = postInfo.Bbcodeoff; postpramsInfo.Parseurloff = postInfo.Parseurloff; postpramsInfo.Allowhtml = postInfo.Htmlon; postpramsInfo.Sdetail = postInfo.Message; postpramsInfo.Showimages = 1 - postInfo.Smileyoff; postpramsInfo.Smiliesinfo = Smilies.GetSmiliesListWithInfo(); postpramsInfo.Customeditorbuttoninfo = Editors.GetCustomEditButtonListWithInfo(); postpramsInfo.Pid = postInfo.Pid; //强制隐藏hide内容 postpramsInfo.Hide = 1; //设定这是为个人空间进行的解析 postpramsInfo.Isforspace = 1; //先简单判断是否是动网兼容模式 if (!postpramsInfo.Ubbmode) message = UBB.UBBToHTML(postpramsInfo); else message = Utils.HtmlEncode(postInfo.Message); if (postpramsInfo.Jammer == 1) message = ForumUtils.AddJammer(postInfo.Message); if (postInfo.Attachment > 0 || regexAttach.IsMatch(message) || regexAttachImg.IsMatch(message)) { //获取在[hide]标签中的附件id string[] attHidArray = GetHiddenAttachIdList(postpramsInfo.Sdetail, postpramsInfo.Hide); ShowtopicPagePostInfo info = new ShowtopicPagePostInfo(); info.Posterid = postInfo.Posterid; info.Pid = postInfo.Pid; for (int i = 0; i < attachmentArray.Length; i++) { ShowtopicPageAttachmentInfo sAtt = new ShowtopicPageAttachmentInfo(); sAtt.Aid = attachmentArray[i].Aid; sAtt.Attachment = attachmentArray[i].Attachment; sAtt.Description = attachmentArray[i].Description; sAtt.Downloads = attachmentArray[i].Downloads; sAtt.Filename = attachmentArray[i].Filename; sAtt.Filesize = attachmentArray[i].Filesize; sAtt.Filetype = attachmentArray[i].Filetype; sAtt.Pid = attachmentArray[i].Pid; sAtt.Postdatetime = attachmentArray[i].Postdatetime; sAtt.Readperm = attachmentArray[i].Readperm; sAtt.Sys_index = attachmentArray[i].Sys_index; sAtt.Sys_noupload = attachmentArray[i].Sys_noupload; sAtt.Tid = attachmentArray[i].Tid; sAtt.Uid = attachmentArray[i].Uid; message = Attachments.GetMessageWithAttachInfo(postpramsInfo, 1, attHidArray, info, sAtt, message); } } return message; }
/// <summary> /// 将单个附件DataRow转换为AttachmentInfo类 /// </summary> /// <param name="drAttach">单个附件DataRow</param> /// <param name="drAttach">是否返回原始路径</param> /// <returns>AttachmentInfo类</returns> private static AttachmentInfo LoadSingleAttachmentInfo(IDataReader drAttach, bool isOriginalFilename) { AttachmentInfo attach = new AttachmentInfo(); if (drAttach.Read()) { attach.Aid = Convert.ToInt32(drAttach["aid"]); attach.Uid = Convert.ToInt32(drAttach["uid"]); attach.Tid = Convert.ToInt32(drAttach["tid"]); attach.Pid = Convert.ToInt32(drAttach["pid"]); attach.Postdatetime = drAttach["postdatetime"].ToString(); attach.Readperm = Convert.ToInt32(drAttach["readperm"]); if (isOriginalFilename) { attach.Filename = drAttach["filename"].ToString(); } else if (drAttach["filename"].ToString().Trim().ToLower().IndexOf("http") < 0) { attach.Filename = "/upload/" + drAttach["filename"].ToString().Trim().Replace("\\", "/"); } else { attach.Filename = drAttach["filename"].ToString().Trim().Replace("\\", "/"); } attach.Description = drAttach["description"].ToString().Trim(); attach.Filetype = drAttach["filetype"].ToString().Trim(); attach.Attachment = drAttach["attachment"].ToString().Trim(); attach.Filesize = Convert.ToInt32(drAttach["filesize"]); attach.Downloads = Convert.ToInt32(drAttach["downloads"]); } drAttach.Close(); return attach; }
/// <summary> /// 更新附件信息 /// </summary> /// <param name="attachmentInfo">附件对象</param> /// <returns>返回被更新的数量</returns> public int UpdateAttachment(AttachmentInfo attachmentInfo) { DbParameter[] parms = { DbHelper.MakeInParam("@aid",(DbType)SqlDbType.Int, 4,attachmentInfo.Aid), DbHelper.MakeInParam("@postdatetime",(DbType)SqlDbType.DateTime, 8, DateTime.Parse(attachmentInfo.Postdatetime)), DbHelper.MakeInParam("@readperm", (DbType)SqlDbType.Int, 4, attachmentInfo.Readperm), DbHelper.MakeInParam("@filename", (DbType)SqlDbType.NChar, 100, attachmentInfo.Filename), DbHelper.MakeInParam("@description", (DbType)SqlDbType.NChar, 100, attachmentInfo.Description), DbHelper.MakeInParam("@filetype", (DbType)SqlDbType.NChar, 50, attachmentInfo.Filetype), DbHelper.MakeInParam("@filesize", (DbType)SqlDbType.Int, 4, attachmentInfo.Filesize), DbHelper.MakeInParam("@attachment", (DbType)SqlDbType.NChar, 100, attachmentInfo.Attachment), DbHelper.MakeInParam("@downloads", (DbType)SqlDbType.Int, 4, attachmentInfo.Downloads), DbHelper.MakeInParam("@tid", (DbType)SqlDbType.Int, 4, attachmentInfo.Tid), DbHelper.MakeInParam("@pid", (DbType)SqlDbType.Int, 4, attachmentInfo.Pid), DbHelper.MakeInParam("@attachprice",(DbType)SqlDbType.Int,4,attachmentInfo.Attachprice), DbHelper.MakeInParam("@width",(DbType)SqlDbType.Int,4,attachmentInfo.Width), DbHelper.MakeInParam("@height",(DbType)SqlDbType.Int,4,attachmentInfo.Height), DbHelper.MakeInParam("@isimage",(DbType)SqlDbType.TinyInt,1,attachmentInfo.Isimage) }; return DbHelper.ExecuteNonQuery(CommandType.StoredProcedure, string.Format("{0}updateallfieldattachmentinfo", BaseConfigs.GetTablePrefix), parms); }
/// <summary> /// 过滤临时内容中的本地临时标签 /// </summary> /// <param name="aid">广告id</param> /// <param name="attachmentinfo">附件信息列表</param> /// <param name="tempMessage">临时信息内容</param> /// <returns>过滤结果</returns> public static string FilterLocalTags(int[] aid, AttachmentInfo[] attachmentinfo, string tempMessage) { Match m; Regex r; for (int i = 0; i < aid.Length; i++) { if (aid[i] > 0) { r = new Regex(@"\[localimg=(\d{1,}),(\d{1,})\]" + attachmentinfo[i].Sys_index + @"\[\/localimg\]", RegexOptions.IgnoreCase); for (m = r.Match(tempMessage); m.Success; m = m.NextMatch()) { tempMessage = tempMessage.Replace(m.Groups[0].ToString(), "[attachimg]" + aid[i] + "[/attachimg]"); } r = new Regex(@"\[local\]" + attachmentinfo[i].Sys_index + @"\[\/local\]", RegexOptions.IgnoreCase); for (m = r.Match(tempMessage); m.Success; m = m.NextMatch()) { tempMessage = tempMessage.Replace(m.Groups[0].ToString(), "[attach]" + aid[i] + "[/attach]"); } } } tempMessage = Regex.Replace(tempMessage, @"\[localimg=(\d{1,}),\s*(\d{1,})\][\s\S]+?\[/localimg\]", string.Empty, RegexOptions.IgnoreCase); tempMessage = Regex.Replace(tempMessage, @"\[local\][\s\S]+?\[/local\]", string.Empty, RegexOptions.IgnoreCase); return tempMessage; }
/// <summary> /// 更新附件信息 /// </summary> /// <param name="attachmentInfo">附件对象</param> /// <returns>返回被更新的数量</returns> public int UpdateAttachment(AttachmentInfo attachmentInfo) { IDataParameter[] parms = { DbHelper.MakeInParam("@aid",(DbType)SqlDbType.Int, 4,attachmentInfo.Aid), DbHelper.MakeInParam("@postdatetime",(DbType)SqlDbType.DateTime, 8, DateTime.Parse(attachmentInfo.Postdatetime)), DbHelper.MakeInParam("@readperm", (DbType)SqlDbType.Int, 4, attachmentInfo.Readperm), DbHelper.MakeInParam("@filename", (DbType)SqlDbType.NChar, 100, attachmentInfo.Filename), DbHelper.MakeInParam("@description", (DbType)SqlDbType.NChar, 100, attachmentInfo.Description), DbHelper.MakeInParam("@filetype", (DbType)SqlDbType.NChar, 50, attachmentInfo.Filetype), DbHelper.MakeInParam("@filesize", (DbType)SqlDbType.Int, 4, attachmentInfo.Filesize), DbHelper.MakeInParam("@attachment", (DbType)SqlDbType.NChar, 100, attachmentInfo.Attachment), DbHelper.MakeInParam("@downloads", (DbType)SqlDbType.Int, 4, attachmentInfo.Downloads) }; string sql = string.Format(@"UPDATE [{0}attachments] SET [postdatetime] = @postdatetime, [readperm] = @readperm, [filename] = @filename, [description] = @description, [filetype] = @filetype, [filesize] = @filesize, [attachment] = @attachment, [downloads] = @downloads WHERE [aid]=@aid", BaseConfigs.GetTablePrefix); return DbHelper.ExecuteNonQuery(CommandType.Text, sql, parms); }
protected override void ShowPage() { pagetitle = "附件下载"; if (attachmentid == -1) { AddErrLine("无效的附件ID"); return; } // 如果当前用户非管理员并且论坛设定了禁止下载附件时间段,当前时间如果在其中的一个时间段内,则不允许用户下载附件 if (useradminid != 1 && usergroupinfo.Disableperiodctrl != 1) { string visitTime = ""; if (Scoresets.BetweenTime(config.Attachbanperiods, out visitTime)) { AddErrLine("在此时间段( " + visitTime + " )内用户不可以下载附件"); return; } } if (DNTRequest.GetString("goodsattach").ToLower() == "yes") GetGoodsAttachInfo(attachmentid); else { // 获取该附件的信息 attachmentinfo = Attachments.GetAttachmentInfo(attachmentid); if (attachmentinfo == null) { AddErrLine("不存在的附件ID"); return; } //当前用户已上传但是还没有绑定到帖子的附件需要特殊处理,直接输出图片 if ((userid > 0 || userid == -1) && userid == attachmentinfo.Uid && attachmentinfo.Tid == 0 && attachmentinfo.Filetype.StartsWith("image/")) { HttpContext.Current.Response.Clear(); if(attachmentinfo.Filename.IndexOf("http") < 0 ) HttpContext.Current.Response.TransmitFile(BaseConfigs.GetForumPath + "upload/" + attachmentinfo.Filename.Trim()); else HttpContext.Current.Response.Redirect(attachmentinfo.Filename.Trim()); HttpContext.Current.Response.End(); return; } // 获取该主题的信息 topic = Topics.GetTopicInfo(attachmentinfo.Tid); if (topic == null) { AddErrLine("不存在的主题ID"); return; } ForumInfo forum = Forums.GetForumInfo(topic.Fid); pagetitle = Utils.RemoveHtml(forum.Name); if (!UserAuthority.VisitAuthority(forum, usergroupinfo, userid, ref msg)) { AddErrLine(msg); if (userid == -1) needlogin = true; return; } //添加判断特殊用户的代码 if (!UserAuthority.CheckUsertAttachAuthority(forum, usergroupinfo, userid, ref msg)) { AddErrLine(msg); if (userid == -1) needlogin = true; return; } ismoder = Moderators.IsModer(useradminid, userid, forum.Fid); // 检查用户是否拥有足够的阅读权限 if ((attachmentinfo.Readperm > usergroupinfo.Readaccess) && (attachmentinfo.Uid != userid) && (!ismoder)) { AddErrLine("您的阅读权限不够"); if (userid == -1) needlogin = true; return; } //检查附件是否存在 if (attachmentinfo.Filename.IndexOf("http") < 0 && !File.Exists(Utils.GetMapPath(string.Format(@"{0}upload/{1}", BaseConfigs.GetForumPath, attachmentinfo.Filename)))) { AddErrLine("该附件文件不存在或已被删除"); return; } //(!Utils.IsImgFilename(attachmentinfo.Filename.Trim()) || config.Showimages != 1):判断文件是否是图片和图片是否允许在帖子中直接显示 //userid != attachmentinfo.Uid && !ismoder:判断当前下载用户是否是该附件的发布者和当前用户是否具有管理权限 //Utils.StrIsNullOrEmpty(Utils.GetCookie("dnt_attachment_" + attachmentid))当前用户是否已经下载过该附件 if ((!Utils.IsImgFilename(attachmentinfo.Filename.Trim()) || config.Showimages != 1) && (userid != attachmentinfo.Uid && !ismoder && Utils.StrIsNullOrEmpty(Utils.GetCookie("dnt_attachment_" + attachmentid)))) { if (Scoresets.IsSetDownLoadAttachScore() && UserCredits.UpdateUserExtCreditsByDownloadAttachment(userid, 1) == -1) { string addExtCreditsTip = ""; if (EPayments.IsOpenEPayments()) addExtCreditsTip = "<br/><span><a href=\"usercpcreditspay.aspx\">点击充值积分</a></span>"; AddErrLine("您的积分不足" + addExtCreditsTip); return; } //设置该附件已经下载的cookie Utils.WriteCookie("dnt_attachment_" + attachmentid, "true", 5); } //检查附件是否存在 if (AttachPaymentLogs.HasBoughtAttach(userid, usergroupinfo.Radminid, attachmentinfo)) { AddErrLine("该附件为交易附件, 请先行购买!"); return; } //如果是图片就不更新下载次数 if (!Utils.IsImgFilename(attachmentinfo.Filename.Trim())) { Attachments.UpdateAttachmentDownloads(attachmentid); } EntLibConfigInfo entLibConfigInfo = EntLibConfigs.GetConfig(); //当使用企业版squid静态文件加速时 if (attachmentinfo.Filename.IndexOf("http") < 0 && entLibConfigInfo != null && !Utils.StrIsNullOrEmpty(entLibConfigInfo.Attachmentdir)) attachmentinfo.Filename = EntLibConfigs.GetConfig().Attachmentdir.TrimEnd('/') + "/" + attachmentinfo.Filename; if (attachmentinfo.Filename.IndexOf("http") < 0) { //当使用mongodb数据库存储附件及相关信息时 if (entLibConfigInfo != null && entLibConfigInfo.Cacheattachfiles.Enable && entLibConfigInfo.Cacheattachfiles.Attachpostid > 0 && entLibConfigInfo.Cacheattachfiles.Attachpostid < attachmentinfo.Pid) Discuz.Cache.Data.DBCacheService.GetAttachFilesService().ResponseFile(attachmentinfo.Filename, Path.GetFileName(attachmentinfo.Attachment), attachmentinfo.Filetype); else Utils.ResponseFile(Utils.GetMapPath(BaseConfigs.GetForumPath + @"upload/" + attachmentinfo.Filename), Path.GetFileName(attachmentinfo.Attachment), attachmentinfo.Filetype); } else { try //添加try语法, 以防止在并发访问情况下, 服务器端远程链接被关闭后出现应用程序 '警告'(事件查看器) { HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Redirect(attachmentinfo.Filename.Trim()); HttpContext.Current.Response.End(); } catch { } } } }