コード例 #1
0
ファイル: DiscuzCloud.cs プロジェクト: Natsuwind/DeepInSummer
        private bool SaveUserAvatar(UserConnectInfo userConnectInfo)
        {
            string formatUid      = Avatars.FormatUid(userConnectInfo.Uid.ToString());
            string avatarFileName = string.Format("{0}avatars/upload/{1}/{2}/{3}/{4}_avatar_",
                                                  BaseConfigs.GetForumPath, formatUid.Substring(0, 3), formatUid.Substring(3, 2), formatUid.Substring(5, 2), formatUid.Substring(7, 2));

            avatarFileName = Utils.GetMapPath(avatarFileName);
            string url = string.Format("http://avatar.connect.discuz.qq.com/{0}/{1}", DiscuzCloudConfigs.GetConfig().Connectappid, userConnectInfo.OpenId);

            if (!Directory.Exists(avatarFileName))
            {
                Utils.CreateDir(avatarFileName);
            }

            if (!Thumbnail.MakeRemoteThumbnailImage(url, avatarFileName + "large.jpg", 200, 200))
            {
                return(false);
            }

            Image tmpImage = Image.FromFile(avatarFileName + "large.jpg");

            if (tmpImage.Width * 0.8 <= 130)
            {
                Thumbnail.MakeThumbnailImage(avatarFileName + "large.jpg", avatarFileName + "medium.jpg",
                                             (int)(tmpImage.Width * 0.8),
                                             (int)(tmpImage.Height * 0.8));
                Thumbnail.MakeThumbnailImage(avatarFileName + "large.jpg", avatarFileName + "small.jpg",
                                             (int)(tmpImage.Width * 0.6),
                                             (int)(tmpImage.Height * 0.6));
            }
            else
            {
                Thumbnail.MakeThumbnailImage(avatarFileName + "large.jpg", avatarFileName + "medium.jpg",
                                             (int)(tmpImage.Width * 0.5),
                                             (int)(tmpImage.Height * 0.5));
                Thumbnail.MakeThumbnailImage(avatarFileName + "large.jpg", avatarFileName + "small.jpg",
                                             (int)(tmpImage.Width * 0.3),
                                             (int)(tmpImage.Height * 0.3));
            }
            try
            {
                tmpImage.Dispose();
            }
            catch { }

            //当支持FTP上传头像时,使用FTP上传远程头像
            if (FTPs.GetForumAvatarInfo.Allowupload == 1)
            {
                FTPs   ftps = new FTPs();
                string ftpAvatarFileName = string.Format("/avatars/upload/{0}/{1}/{2}/",
                                                         formatUid.Substring(0, 3), formatUid.Substring(3, 2), formatUid.Substring(5, 2));
                ftps.UpLoadFile(ftpAvatarFileName, avatarFileName + "large.jpg", FTPs.FTPUploadEnum.ForumAvatar);
                ftps.UpLoadFile(ftpAvatarFileName, avatarFileName + "medium.jpg", FTPs.FTPUploadEnum.ForumAvatar);
                ftps.UpLoadFile(ftpAvatarFileName, avatarFileName + "small.jpg", FTPs.FTPUploadEnum.ForumAvatar);
            }
            return(true);
        }
コード例 #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                int pertask = DNTRequest.GetInt("pertask", 0);
                int lastnumber = DNTRequest.GetInt("lastnumber", 0);
                int startvalue = DNTRequest.GetInt("startvalue", 0);
                int endvalue = DNTRequest.GetInt("endvalue", 0);
                string resultmessage = "";
                switch (Request.Params["opname"])
                {
                    case "UpdatePostSP":
                        AdminForumStats.UpdatePostSP(pertask, ref lastnumber);
                        resultmessage = lastnumber.ToString();
                        break;
                    case "UpdateMyPost":
                        AdminForumStats.UpdateMyPost(pertask, ref lastnumber);
                        resultmessage = lastnumber.ToString();
                        break;
                    case "ReSetFourmTopicAPost":
                        //AdminForumStats.ReSetFourmTopicAPost(pertask, ref lastnumber);
                        AdminForumStats.ReSetFourmTopicAPost();
                        resultmessage = "-1";
                        break;
                    case "ReSetUserDigestPosts":
                        //AdminForumStats.ReSetUserDigestPosts(pertask, ref lastnumber);
                        //resultmessage = lastnumber.ToString();
                        AdminForumStats.ReSetUserDigestPosts();
                        resultmessage = "-1";
                        break;
                    case "ReSetUserPosts":
                        AdminForumStats.ReSetUserPosts(pertask, ref lastnumber);
                        resultmessage = lastnumber.ToString();
                        break;
                    case "ReSetTopicPosts":
                        AdminForumStats.ReSetTopicPosts(pertask, ref lastnumber);
                        resultmessage = lastnumber.ToString();
                        break;
                    case "ReSetFourmTopicAPost_StartEnd":
                        AdminForumStats.ReSetFourmTopicAPost(startvalue, endvalue);
                        resultmessage = "1";
                        break;
                    case "ReSetUserDigestPosts_StartEnd":
                        AdminForumStats.ReSetUserDigestPosts(startvalue, endvalue);
                        resultmessage = "1";
                        break;
                    case "ReSetUserPosts_StartEnd":
                        AdminForumStats.ReSetUserPosts(startvalue, endvalue);
                        resultmessage = "1";
                        break;
                    case "ReSetTopicPosts_StartEnd":
                        AdminForumStats.ResetLastRepliesInfoOfTopics(startvalue, endvalue);
                        resultmessage = "1";
                        break;
                    case "ftptest":
                        FTPs ftps = new FTPs();
                        string message = "";
                        bool ok = ftps.TestConnect(DNTRequest.GetString("serveraddress"), DNTRequest.GetInt("serverport", 0), DNTRequest.GetString("username"),
                            DNTRequest.GetString("password"), DNTRequest.GetInt("timeout", 0), DNTRequest.GetString("uploadpath"), ref message);
                        resultmessage = ok ? "ok" : "Զ�̸������ò��Գ��ִ���\n������" + message;
                        break;
                    case "setapp":
                        APIConfigInfo aci = APIConfigs.GetConfig();
                        aci.Enable = DNTRequest.GetString("allowpassport") == "1";
                        APIConfigs.SaveConfig(aci);
                        resultmessage = "ok";
                        break;
                    case "location":
                        string city = DNTRequest.GetString("city");
                        resultmessage = "ok";
                        DataTable dt = MallPluginProvider.GetInstance().GetLocationsTable();
                        foreach (DataRow dr in dt.Rows)
                        {
                            if (dr["country"].ToString() == DNTRequest.GetString("country") && dr["state"].ToString() == DNTRequest.GetString("state") && dr["city"].ToString() == city)
                            {
                               resultmessage = "<img src='../images/false.gif' title='" + city + "�Ѿ�����!'>";
                                break;
                            }
                        }
                        break;
                    case "goodsinfo":
                        int goodsid = DNTRequest.GetInt("goodsid", 0);
                        Goodsinfo goodsinfo = MallPluginProvider.GetInstance().GetGoodsInfo(goodsid);
                        if (goodsinfo == null)
                        {
                            resultmessage = "��Ʒ������!";
                            break;
                        }
                        //GoodsattachmentinfoCollection attachmentinfos = GoodsAttachments.GetGoodsAttachmentsByGoodsid(goodsinfo.Goodsid);
                        //string img = "";
                        //if (attachmentinfos != null)
                        //{
                        //    img = attachmentinfos[0].Filename;
                        //}
                        PostpramsInfo param = new PostpramsInfo();
                        param.Allowhtml = 1;
                        param.Showimages = 1;
                        param.Sdetail = goodsinfo.Message;
                        resultmessage = "<table width='100%'><tr><td>" + UBB.UBBToHTML(param) + "</td></tr></table>";
                        break;
                    case "downloadword":
                        dt = BanWords.GetBanWordList();
                        string words = "";
                        if (dt.Rows.Count > 0)
                        {
                            for (int i = 0; i < dt.Rows.Count; i++)
                            {
                                words += dt.Rows[i][2].ToString() + "=" + dt.Rows[i][3].ToString() + "\r\n";
                            }
                        }

                        string filename = "words.txt";
                        HttpContext.Current.Response.Clear();
                        HttpContext.Current.Response.Buffer = false;
                        HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
                        HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + Server.UrlEncode(filename));
                        HttpContext.Current.Response.ContentType = "text/plain";
                        HttpContext.Current.Response.Write(words);
                        HttpContext.Current.Response.End();
                        break;

                    case "gettopicinfo":
                        StringBuilder sb = new StringBuilder();
                        TopicInfo info = Topics.GetTopicInfo(DNTRequest.GetInt("tid", 0));
                        sb.Append("[");
                        if (info != null)
                        {

                           sb.Append(string.Format("{{'tid':{0},'title':'{1}'}}", info.Tid, info.Title));
                        }

                        System.Web.HttpContext.Current.Response.Clear();
                        System.Web.HttpContext.Current.Response.ContentType = "application/json";
                        System.Web.HttpContext.Current.Response.Expires = 0;
                        System.Web.HttpContext.Current.Response.Cache.SetNoStore();
                        System.Web.HttpContext.Current.Response.Write(sb.Append("]").ToString());
                        System.Web.HttpContext.Current.Response.End();
                        break;
                }
                Response.Write(resultmessage);
                Response.ExpiresAbsolute = DateTime.Now.AddSeconds(-1);
                Response.Expires = -1;
                Response.End();
            }
        }
コード例 #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                int pertask = DNTRequest.GetInt("pertask", 0);
                int lastnumber = DNTRequest.GetInt("lastnumber", 0);
                int startvalue = DNTRequest.GetInt("startvalue", 0);
                int endvalue = DNTRequest.GetInt("endvalue", 0);
                string resultmessage = "";
                switch (Request.Params["opname"])
                {
                    case "UpdatePostSP":
                        AdminForumStats.UpdatePostSP(pertask, ref lastnumber);
                        resultmessage = lastnumber.ToString();
                        break;
                    case "UpdateMyPost":
                        AdminForumStats.UpdateMyPost(pertask, ref lastnumber);
                        resultmessage = lastnumber.ToString();
                        break;
                    case "ReSetFourmTopicAPost":
                        //AdminForumStats.ReSetFourmTopicAPost(pertask, ref lastnumber);
                        AdminForumStats.ReSetFourmTopicAPost();
                        resultmessage = "-1";
                        break;
                    case "ReSetUserDigestPosts":
                        //AdminForumStats.ReSetUserDigestPosts(pertask, ref lastnumber);
                        //resultmessage = lastnumber.ToString();
                        AdminForumStats.ReSetUserDigestPosts();
                        resultmessage = "-1";
                        break;
                    case "ReSetUserPosts":
                        AdminForumStats.ReSetUserPosts(pertask, ref lastnumber);
                        resultmessage = lastnumber.ToString();
                        break;
                    case "ReSetTopicPosts":
                        AdminForumStats.ReSetTopicPosts(pertask, ref lastnumber);
                        resultmessage = lastnumber.ToString();
                        break;
                    case "ReSetFourmTopicAPost_StartEnd":
                        AdminForumStats.ReSetFourmTopicAPost(startvalue, endvalue);
                        resultmessage = "1";
                        break;
                    case "ReSetUserDigestPosts_StartEnd":
                        AdminForumStats.ReSetUserDigestPosts(startvalue, endvalue);
                        resultmessage = "1";
                        break;
                    case "ReSetUserPosts_StartEnd":
                        AdminForumStats.ReSetUserPosts(startvalue, endvalue);
                        resultmessage = "1";
                        break;
                    case "ReSetTopicPosts_StartEnd":
                        AdminForumStats.ResetLastRepliesInfoOfTopics(startvalue, endvalue);
                        resultmessage = "1";
                        break;
                    case "ftptest":
                        FTPs ftps = new FTPs();
                        string message = "";
                        bool ok = ftps.TestConnect(DNTRequest.GetString("serveraddress"), DNTRequest.GetInt("serverport", 0), DNTRequest.GetString("username"), 
                            DNTRequest.GetString("password"), DNTRequest.GetInt("timeout", 0), DNTRequest.GetString("uploadpath"), ref message);
                        resultmessage = ok ? "ok" : "远程附件设置测试出现错误!\n描述:" + message;
                        break;
                    case "setapp":
                        APIConfigInfo aci = APIConfigs.GetConfig();
                        aci.Enable = DNTRequest.GetString("allowpassport") == "1";
                        APIConfigs.SaveConfig(aci);
                        resultmessage = "ok";
                        break;
                    case "location":
                        string city = DNTRequest.GetString("city");
                        resultmessage = "ok";
                        DataTable dt = MallPluginProvider.GetInstance().GetLocationsTable();
                        foreach (DataRow dr in dt.Rows)
                        {
                            if (dr["country"].ToString() == DNTRequest.GetString("country") && dr["state"].ToString() == DNTRequest.GetString("state") && dr["city"].ToString() == city)
                            {
                               resultmessage = "<img src='../images/false.gif' title='" + city + "已经存在!'>";
                                break;
                            }
                        }
                        break;
                    case "goodsinfo":
                        int goodsid = DNTRequest.GetInt("goodsid", 0);
                        Goodsinfo goodsinfo = MallPluginProvider.GetInstance().GetGoodsInfo(goodsid);
                        if (goodsinfo == null)
                        {
                            resultmessage = "商品不存在!";
                            break;
                        }
                        //GoodsattachmentinfoCollection attachmentinfos = GoodsAttachments.GetGoodsAttachmentsByGoodsid(goodsinfo.Goodsid);
                        //string img = "";
                        //if (attachmentinfos != null)
                        //{
                        //    img = attachmentinfos[0].Filename;
                        //}
                        PostpramsInfo param = new PostpramsInfo();
                        param.Allowhtml = 1;
                        param.Showimages = 1;
                        param.Sdetail = goodsinfo.Message;
                        resultmessage = "<table width='100%'><tr><td>" + UBB.UBBToHTML(param) + "</td></tr></table>";
                        break;
                    case "downloadword":
                        dt = BanWords.GetBanWordList();
                        string words = "";
                        if (dt.Rows.Count > 0)
                        {
                            for (int i = 0; i < dt.Rows.Count; i++)
                            {
                                words += dt.Rows[i][2].ToString() + "=" + dt.Rows[i][3].ToString() + "\r\n";
                            }
                        }

                        string filename = "words.txt";
                        HttpContext.Current.Response.Clear();
                        HttpContext.Current.Response.Buffer = false;
                        HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
                        HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + Server.UrlEncode(filename));
                        HttpContext.Current.Response.ContentType = "text/plain";
                        HttpContext.Current.Response.Write(words);
                        HttpContext.Current.Response.End();
                        break;

                    case "gettopicinfo":
                        StringBuilder sb = new StringBuilder();
                        TopicInfo info = Topics.GetTopicInfo(DNTRequest.GetInt("tid", 0));
                        sb.Append("[");
                        if (info != null)
                        {
                           sb.Append(string.Format("{{'tid':{0},'title':'{1}'}}", info.Tid, info.Title));
                        }

                        System.Web.HttpContext.Current.Response.Clear();
                        System.Web.HttpContext.Current.Response.ContentType = "application/json";
                        System.Web.HttpContext.Current.Response.Expires = 0;
                        System.Web.HttpContext.Current.Response.Cache.SetNoStore();
                        System.Web.HttpContext.Current.Response.Write(sb.Append("]").ToString());
                        System.Web.HttpContext.Current.Response.End();
                        break;

                    case "DeletePrivateMessages"://批量删除短消息
                        {
                            resultmessage = PrivateMessages.DeletePrivateMessages(DNTRequest.GetString("isnew") == "true", DNTRequest.GetString("postdatetime"), DNTRequest.GetString("msgfromlist"), DNTRequest.GetString("lowerupper") == "true", DecodeChar(DNTRequest.GetString("subject")), DecodeChar(DNTRequest.GetString("message")), DNTRequest.GetString("isupdateusernewpm") == "true");
                            resultmessage = string.Format("[{{'count':'{0}'}}]", resultmessage);
                            System.Threading.Thread.Sleep(4000);/*暂停4秒,以减轻数据库压力*/
                            break;
                        }
                    case "sendsmtogroup"://批量发送短消息
                        {
                            int start_uid = DNTRequest.GetInt("start_uid", 0);
                            resultmessage = Users.SendPMByGroupidList(DNTRequest.GetString("groupidlist"), DNTRequest.GetInt("topnumber", 0),
                                ref start_uid,
                                DNTRequest.GetString("msgfrom"), DNTRequest.GetInt("msguid", 1), DNTRequest.GetInt("folder", 0),
                                DecodeChar(DNTRequest.GetString("subject")), DNTRequest.GetString("postdatetime"), DecodeChar(DNTRequest.GetString("message"))).ToString();
                            resultmessage = string.Format("[{{'startuid':{0},'count':'{1}'}}]", start_uid, resultmessage);
                            System.Threading.Thread.Sleep(4000);/*暂停4秒,以减轻数据库压力*/
                            break;
                        }
                    case "usergroupsendemail"://批量发送邮件
                        {
                            int start_uid = DNTRequest.GetInt("start_uid", 0);
                            resultmessage = Users.SendEmailByGroupidList(DNTRequest.GetString("groupidlist"), DNTRequest.GetInt("topnumber", 0),
                                ref start_uid, DecodeChar(DNTRequest.GetString("subject")), DecodeChar(DNTRequest.GetString("body"))).ToString();
                            resultmessage = string.Format("[{{'startuid':{0},'count':'{1}'}}]", start_uid, resultmessage);
                            System.Threading.Thread.Sleep(4000);/*暂停4秒,以减轻数据库压力*/
                            break;
                        }
                    case "updateusercreditbyformula"://根据积分公式批量更新用户积分
                        {
                            int start_uid = DNTRequest.GetInt("start_uid", 0);
                            resultmessage = Users.UpdateUserCredits(DecodeChar(DNTRequest.GetString("formula")), start_uid).ToString();
                            resultmessage = string.Format("[{{'startuid':{0},'count':'{1}'}}]", start_uid + 100 /*每次递增100条记录*/, resultmessage);
                            System.Threading.Thread.Sleep(4000);/*暂停4秒,以减轻数据库压力*/
                            break;
                        }
                }
                System.Web.HttpContext.Current.Response.Clear();
                System.Web.HttpContext.Current.Response.Expires = 0;
                System.Web.HttpContext.Current.Response.Cache.SetNoStore();
                Response.Write(resultmessage);
                Response.ExpiresAbsolute = DateTime.Now.AddSeconds(-1);
                Response.Expires = -1;
                Response.End();
            }
        }
コード例 #4
0
ファイル: MixObjects.cs プロジェクト: Vinna/DeepInSummer
        public AttachmentInfo StoreFileAdvanced(string fileName, byte[] data, int dataLength, string parameters, bool firstChunk, bool lastChunk, CredentialInfo creinfo)
        {
            if (AuthenticateUser(creinfo))
            {
                UploadSetInfo uploadSetInfo = GetAttachmentUploadSet(creinfo);
                string fileextname = Utils.CutString(fileName, fileName.LastIndexOf(".") + 1).ToLower();

                if (uploadSetInfo.CanPostAttach && uploadSetInfo.AttachExtensionsNoSize.IndexOf(fileextname) >= 0 && uploadSetInfo.AttachSize > dataLength &&
                    Utils.StrIsNullOrEmpty(uploadSetInfo.ErrMessage))
                {
                    string uploadFolder = GetUploadFolder(fileName, creinfo.ForumID.ToString());
                    string tempFileName = fileName + _tempExtension;

                    if (firstChunk)
                    {
                        //删除临时文件
                        if (File.Exists(@HostingEnvironment.ApplicationPhysicalPath + "/upload/temp/" + tempFileName))
                            File.Delete(@HostingEnvironment.ApplicationPhysicalPath + "/upload/temp/" + tempFileName);

                        //删除目录文件
                        if (File.Exists(uploadFolder + "/" + fileName))
                            File.Delete(uploadFolder + "/" + fileName);
                    }


                    FileStream fs = File.Open(@HostingEnvironment.ApplicationPhysicalPath + "/upload/temp/" + tempFileName, FileMode.Append);
                    fs.Write(data, 0, dataLength);
                    fs.Close();
                    fs.Dispose();
                    if (lastChunk)
                    {
                        lock (lockHelper)
                        {
                            string newfilename = (Environment.TickCount & int.MaxValue).ToString() + new Random().Next(1000, 9999) + "." + fileextname;
                            File.Move(HostingEnvironment.ApplicationPhysicalPath + "/upload/temp/" + tempFileName, uploadFolder + "/" + newfilename);
                         
                            try
                            {
                                //当支持FTP上传附件时,使用FTP上传远程附件
                                if (FTPs.GetForumAttachInfo != null && FTPs.GetForumAttachInfo.Allowupload == 1)
                                {
                                    FTPs ftps = new FTPs();
                                    //当不保留本地附件模式时,在上传完成之后删除本地tempfilename文件
                                    ftps.UpLoadFile(newfilename, uploadFolder + "/" + newfilename, FTPs.FTPUploadEnum.ForumAttach);
                                }
                            }
                            catch
                            {
                                ;
                            }
                            return Attachments.GetAttachmentInfo(AddAttachment(newfilename, fileName, creinfo));
                        }
                    }
                }
            }
            return null;
        }
コード例 #5
0
        protected override void ShowPage()
        {
            pagetitle = "用户控制面板";

            if (userid == -1)
            {
                AddErrLine("你尚未登录");
                return;
            }
            user = Users.GetUserInfo(userid);

            if (config.Enablealbum != 1)
            {
                AddErrLine("相册功能已被关闭");
                return;
            }
            if (albumid < 1)
            {
                AddErrLine("指定的相册不存在");
                return;
            }
            AlbumInfo albuminfo = DTOProvider.GetAlbumInfo(albumid);
            if (this.userid != albuminfo.Userid)
            {
                AddErrLine("您无权限在该相册内添加照片");
                return;
            }           

            enabletag = config.Enabletag == 1;
            freephotosize = UserGroups.GetUserGroupInfo(usergroupid).Maxspacephotosize - Data.DbProvider.GetInstance().GetPhotoSizeByUserid(userid);            
            albumname = albuminfo.Title;
           
            if (DNTRequest.IsPost())
            {
                if (ForumUtils.IsCrossSitePost())
                {
                    AddErrLine("您的请求来路不正确,无法提交。如果您安装了某种默认屏蔽来路信息的个人防火墙软件(如 Norton Internet Security),请设置其不要禁止来路信息后再试。");
                    return;
                }

                HttpFileCollection files = HttpContext.Current.Request.Files;
                int imgcount = 0;

                for (int iFile = 0; iFile < files.Count; iFile++)
                {
                    HttpPostedFile postedFile = files[iFile];
                    if (postedFile == null || postedFile.FileName == "")
                        continue;
                    string fileName, fileExtension;
                    fileName = Path.GetFileName(postedFile.FileName);
                    fileExtension = Path.GetExtension(fileName).ToLower();
                    if (fileExtension != ".jpg" && fileExtension != ".gif" && fileExtension != ".png" && fileExtension != ".jpeg")
                        continue;
                    
                    //判断用户是否达到了照片最大上传数
                    int filesize = postedFile.ContentLength;
                    if (freephotosize < filesize)
                    {
                        AddErrLine("照片上传空间数已满,某些照片不能再上传!<br />如果想继续上传,请删除以前旧照片!");
                        return;
                    }
                    string phototitle = DNTRequest.GetFormString("phototitle" + (iFile + 1));
                    PhotoInfo spacephotoinfo = new PhotoInfo();
                    spacephotoinfo.Title = Utils.StrIsNullOrEmpty(phototitle) ? fileName.Remove(fileName.IndexOf("."), 1) : phototitle;
                    spacephotoinfo.Albumid = albumid;
                    spacephotoinfo.Userid = userid;
                    string[] currentdate = DateTime.Now.ToString("yyyy-MM-dd").Split('-');
                    string uploaddir = "";

                    //当支持FTP上传远程照片
                    if (FTPs.GetAlbumAttachInfo.Allowupload == 1)
                    {
                        //当不保留本地附件模式时
                        if (FTPs.GetAlbumAttachInfo.Reservelocalattach == 0)
                            uploaddir = Utils.GetMapPath(BaseConfigs.GetForumPath + "space/upload/temp/");
                        else
                            uploaddir = Utils.GetMapPath(BaseConfigs.GetForumPath + "space/upload/" + currentdate[0] + "/" + currentdate[1] + "/" + currentdate[2] + "/");

                        if (!Directory.Exists(uploaddir))
                            Utils.CreateDir(uploaddir);

                        string ftpfilename = Globals.UploadSpaceFile(postedFile, uploaddir, true);
                        spacephotoinfo.Filename = FTPs.GetAlbumAttachInfo.Remoteurl+ "/" + currentdate[0] + "/" + currentdate[1] + "/" + currentdate[2] + "/" + ftpfilename;

                        FTPs ftps = new FTPs();
                        ftps.UpLoadFile("/" + currentdate[0] + "/" + currentdate[1] + "/" + currentdate[2] + "/" ,
                                        uploaddir + ftpfilename,
                                        FTPs.FTPUploadEnum.AlbumAttach);
                        ftps = new FTPs();
                        ftps.UpLoadFile("/" + currentdate[0] + "/" + currentdate[1] + "/" + currentdate[2] + "/" ,
                                        uploaddir + Globals.GetThumbnailImage(ftpfilename),
                                        FTPs.FTPUploadEnum.AlbumAttach);
                        ftps = new FTPs();
                        ftps.UpLoadFile("/" + currentdate[0] + "/" + currentdate[1] + "/" + currentdate[2] + "/" ,
                                        uploaddir + Globals.GetSquareImage(ftpfilename),
                                        FTPs.FTPUploadEnum.AlbumAttach);
                    }
                    else 
                    {
                        uploaddir = Utils.GetMapPath(BaseConfigs.GetForumPath + "space/upload/" + currentdate[0] + "/" + currentdate[1] + "/" + currentdate[2] + "/");
                        if (!Directory.Exists(uploaddir))
                            Utils.CreateDir(uploaddir);

                        spacephotoinfo.Filename = "space/upload/" + currentdate[0] + "/" + currentdate[1] + "/" + currentdate[2] + "/" + Globals.UploadSpaceFile(postedFile, uploaddir, true);
                    }
                    
                    spacephotoinfo.Attachment = fileName;
                    spacephotoinfo.Description = DNTRequest.GetFormString("description" + (iFile + 1));
                    spacephotoinfo.Filesize = filesize;
                    spacephotoinfo.Username = username;
                    spacephotoinfo.IsAttachment = 0;
                    freephotosize -= filesize;
                    int photoid = Data.DbProvider.GetInstance().AddSpacePhoto(spacephotoinfo);
                    string tags = DNTRequest.GetString("phototag" + (iFile + 1)).Trim();
                    string[] tagsArray = null;
                    if (enabletag && tags != string.Empty)
                    {
                        tagsArray = Utils.SplitString(tags, " ", true, 10);
                        if (tagsArray.Length > 0)
                        {
                            Data.DbProvider.GetInstance().CreatePhotoTags(string.Join(" ", tagsArray), photoid, userid, Utils.GetDateTime());
                            AlbumTags.WritePhotoTagsCacheFile(photoid);
                        }
                    }
                    imgcount++;
                }
                if (imgcount != 0)
                {
                    AlbumInfo albumInfo = DTOProvider.GetAlbumInfo(albumid);
                    albumInfo.Imgcount = Data.DbProvider.GetInstance().GetSpacePhotoCountByAlbumId(albumid);
                    Data.DbProvider.GetInstance().SaveSpaceAlbum(albumInfo);
                }
                else
                {
                    AddErrLine("没有符合要求的图片,请上传jpg,jpeg,gif,png格式的图片");
                    return;
                }

                //生成json数据
                Albums.CreateAlbumJsonData(albumid);                
                Albums.CreatePhotoImageByAlbum(albumid);

                SetUrl(string.Format("usercpspacemanagephoto.aspx?albumid={0}", albumid));
                SetMetaRefresh();
                SetShowBackLink(true);
                AddMsgLine("照片增加完毕");
            }
        }
コード例 #6
0
ファイル: MallUtils.cs プロジェクト: Vinna/DeepInSummer
        /// <summary>
        /// 保存上传的文件
        /// </summary>
        /// <param name="categoryid">商品分类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 Goodsattachmentinfo[] SaveRequestFiles(int categoryId, int MaxAllowFileCount, int MaxSizePerDay, int MaxFileSize, int TodayUploadedSize, string AllowFileType, int waterMarkStatus, GeneralConfigInfo config, string fileKey)
        {
            string[] tmp = Utils.SplitString(AllowFileType, "\r\n");
            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++;
            }

            Goodsattachmentinfo[] attachmentInfo = new Goodsattachmentinfo[saveFileCount];
            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 = "";

                    attachmentInfo[saveFileCount] = new Goodsattachmentinfo();

                    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/mall/");
                            StringBuilder saveDir = new StringBuilder("");
                            //附件保存方式 0=按年/月/日存入不同目录 1=按年/月/日/论坛存入不同目录 2=按论坛存入不同目录 3=按文件类型存入不同目录
                            if (config.Attachsave == 1)
                            {
                                saveDir.Append(DateTime.Now.ToString("yyyy"));
                                saveDir.Append(Path.DirectorySeparatorChar);
                                saveDir.Append(DateTime.Now.ToString("MM"));
                                saveDir.Append(Path.DirectorySeparatorChar);
                                saveDir.Append(DateTime.Now.ToString("dd"));
                                saveDir.Append(Path.DirectorySeparatorChar);
                                saveDir.Append(categoryId.ToString());
                                saveDir.Append(Path.DirectorySeparatorChar);
                            }
                            else if (config.Attachsave == 2)
                            {
                                saveDir.Append(categoryId);
                                saveDir.Append(Path.DirectorySeparatorChar);
                            }
                            else if (config.Attachsave == 3)
                            {
                                saveDir.Append(fileExtName);
                                saveDir.Append(Path.DirectorySeparatorChar);
                            }
                            else
                            {
                                saveDir.Append(DateTime.Now.ToString("yyyy"));
                                saveDir.Append(Path.DirectorySeparatorChar);
                                saveDir.Append(DateTime.Now.ToString("MM"));
                                saveDir.Append(Path.DirectorySeparatorChar);
                                saveDir.Append(DateTime.Now.ToString("dd"));
                                saveDir.Append(Path.DirectorySeparatorChar);
                            }


                            newFileName = (Environment.TickCount & int.MaxValue).ToString() + i + random.Next(1000, 9999) + "." + fileExtName;

                            //临时文件名称变量. 用于当启动远程附件之后,先上传到本地临时文件夹的路径信息
                            string tempFileName = "";
                            //当支持FTP上传附件且不保留本地附件时
                            if (FTPs.GetMallAttachInfo.Allowupload == 1 && FTPs.GetMallAttachInfo.Reservelocalattach == 0)
                            {
                                // 如果指定目录不存在则建立临时路径
                                if (!Directory.Exists(UploadDir + "temp\\"))
                                    Utils.CreateDir(UploadDir + "temp\\");

                                tempFileName = "temp\\" + newFileName;
                            }
                            else
                            {
                                // 如果指定目录不存在则建立
                                if (!Directory.Exists(UploadDir + saveDir.ToString()))
                                    Utils.CreateDir(UploadDir + saveDir.ToString());
                            }
                            newFileName = saveDir.ToString() + 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;

                                    if (attachmentInfo[saveFileCount].Sys_noupload == "")
                                    {
                                        if (waterMarkStatus == 0)
                                        {
                                            //当支持FTP上传附件且不保留本地附件模式时,则先上传到临时目录下
                                            if (FTPs.GetMallAttachInfo.Allowupload == 1 && FTPs.GetMallAttachInfo.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.GetMallAttachInfo.Allowupload == 1 && FTPs.GetMallAttachInfo.Reservelocalattach == 0)
                                                    ForumUtils.AddImageSignPic(img, UploadDir + tempFileName, Utils.GetMapPath(BaseConfigs.GetForumPath + "watermark/" + config.Watermarkpic), config.Watermarkstatus, config.Attachimgquality, config.Watermarktransparency);
                                                else
                                                    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());

                                                //当支持FTP上传附件且不保留本地附件模式时,则先上传到临时目录下
                                                if (FTPs.GetMallAttachInfo.Allowupload == 1 && FTPs.GetMallAttachInfo.Reservelocalattach == 0)
                                                    ForumUtils.AddImageSignText(img, UploadDir + tempFileName, watermarkText, config.Watermarkstatus, config.Attachimgquality, config.Watermarkfontname, config.Watermarkfontsize);
                                                else
                                                    ForumUtils.AddImageSignText(img, UploadDir + newFileName, watermarkText, config.Watermarkstatus, config.Attachimgquality, config.Watermarkfontname, config.Watermarkfontsize);
                                            }

                                            //当支持FTP上传附件且不保留本地附件模式时,则读取临时目录下的文件信息
                                            if (FTPs.GetMallAttachInfo.Allowupload == 1 && FTPs.GetMallAttachInfo.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.GetMallAttachInfo.Allowupload == 1 && FTPs.GetMallAttachInfo.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.GetMallAttachInfo.Allowupload == 1 && FTPs.GetMallAttachInfo.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.GetMallAttachInfo.Allowupload == 1) ? true : false;
                                    //当支持FTP上传附件且不保留本地附件模式时
                                    if (FTPs.GetMallAttachInfo.Allowupload == 1 && FTPs.GetMallAttachInfo.Reservelocalattach == 0)
                                        preview.OnSaved(UploadDir + tempFileName);
                                    else
                                        preview.OnSaved(UploadDir + newFileName);
                                }
                            }
                            catch
                            { }

                            //当支持FTP上传附件时,使用FTP上传远程附件
                            if (FTPs.GetMallAttachInfo.Allowupload == 1)
                            {
                                FTPs ftps = new FTPs();
                                //当不保留本地附件模式时,在上传完成之后删除本地tempfilename文件
                                if (FTPs.GetMallAttachInfo.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);
                            }
                        }
                        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.GetMallAttachInfo.Allowupload == 1)
                        attachmentInfo[saveFileCount].Filename = FTPs.GetMallAttachInfo.Remoteurl + "/" + newFileName.Replace("\\", "/");
                    else
                        attachmentInfo[saveFileCount].Filename = "mall/" + newFileName;

                    attachmentInfo[saveFileCount].Description = fileExtName;
                    attachmentInfo[saveFileCount].Filetype = fileType;
                    attachmentInfo[saveFileCount].Attachment = fileName;
                    attachmentInfo[saveFileCount].Postdatetime = DateTime.Now.ToString();
                    attachmentInfo[saveFileCount].Sys_index = i;
                    saveFileCount++;
                }
            }
            return attachmentInfo;
        }
コード例 #7
0
ファイル: MallUtils.cs プロジェクト: Vinna/DeepInSummer
        /// <summary>
        /// 上传店标文件
        /// </summary>
        /// <param name="MaxFileSize">最大文件上传尺寸</param>
        /// <param name="AllowFileType">允许上传文件类型</param>
        /// <param name="config">配置对象信息</param>
        /// <param name="filekey">File控件的Key(即Name属性)</param>
        /// <returns>文件信息结构</returns>
        public static string SaveRequestFile(int MaxFileSize, string AllowFileType, GeneralConfigInfo config, string filekey)
        {            
            string[] tmp = Utils.SplitString(AllowFileType, "\r\n");
     
            Random random = new Random(unchecked((int)DateTime.Now.Ticks));

            for (int i = 0; i < HttpContext.Current.Request.Files.Count; 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 = "";
                   
                    // 判断 文件扩展名/文件大小/文件类型 是否符合要求
                    if (!(Utils.IsImgFilename(fileName) && !fileType.StartsWith("image")))
                    {
                        int extNameId = Utils.GetInArrayID(fileExtName, tmp);

                        if (extNameId >= 0 && MaxFileSize >= fileSize)
                        {
                            string UploadDir = Utils.GetMapPath(BaseConfigs.GetForumPath + "upload/mall/");
                            StringBuilder savedir = new StringBuilder("");
                                savedir.Append(DateTime.Now.ToString("yyyy"));
                                savedir.Append(Path.DirectorySeparatorChar);
                                savedir.Append(DateTime.Now.ToString("MM"));
                                savedir.Append(Path.DirectorySeparatorChar);
                                savedir.Append(DateTime.Now.ToString("dd"));
                                savedir.Append(Path.DirectorySeparatorChar);

                            newFileName = (Environment.TickCount & int.MaxValue).ToString() + i.ToString() + random.Next(1000, 9999).ToString() + "." + fileExtName;

                            //临时文件名称变量. 用于当启动远程附件之后,先上传到本地临时文件夹的路径信息
                            string tempfilename = "";
                            //当支持FTP上传附件且不保留本地附件时
                            if (FTPs.GetMallAttachInfo.Allowupload == 1 && FTPs.GetMallAttachInfo.Reservelocalattach == 0)
                            {
                                // 如果指定目录不存在则建立临时路径
                                if (!Directory.Exists(UploadDir + "temp\\"))
                                    Utils.CreateDir(UploadDir + "temp\\");

                                tempfilename = "temp\\" + newFileName;
                            }
                            else
                            {
                                // 如果指定目录不存在则建立
                                if (!Directory.Exists(UploadDir + savedir.ToString()))
                                    Utils.CreateDir(UploadDir + savedir.ToString());
                            }
                            newFileName = savedir.ToString() + newFileName;

                            try
                            {
                                //当上传目录和临时文件夹都没有上传的文件时
                                if (!(Utils.FileExists(UploadDir + tempfilename)) && (!(Utils.FileExists(UploadDir + newFileName))))
                                {

                                    //当支持FTP上传附件且不保留本地附件模式时,则先上传到临时目录下
                                    if (FTPs.GetMallAttachInfo.Allowupload == 1 && FTPs.GetMallAttachInfo.Reservelocalattach == 0)
                                        HttpContext.Current.Request.Files[i].SaveAs(UploadDir + tempfilename);
                                    else
                                        HttpContext.Current.Request.Files[i].SaveAs(UploadDir + newFileName);
                                }
                            }
                            catch
                            {}

                            //当支持FTP上传附件时,使用FTP上传远程附件
                            if (FTPs.GetMallAttachInfo.Allowupload == 1)
                            {
                                FTPs ftps = new FTPs();

                                //当不保留本地附件模式时,在上传完成之后删除本地tempfilename文件
                                if (FTPs.GetMallAttachInfo.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);
                            }
                        }
                        else
                           return (extNameId < 0) ? "文件格式无效" : "文件大于单个文件允许上传的字节数";
                    }
                    else
                        return "文件格式无效";

                    //当支持FTP上传附件时
                    if (FTPs.GetMallAttachInfo.Allowupload == 1)
                        return FTPs.GetMallAttachInfo.Remoteurl + "/" + newFileName.Replace("\\", "/");
                    else
                        return "mall/" + newFileName;
                }
            }
            return "";
        }
コード例 #8
0
ファイル: ForumUtils.cs プロジェクト: hanshion/DiscuzNt
        /// <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;
        }
コード例 #9
0
ファイル: ForumUtils.cs プロジェクト: simazhao/discuz-nt
        /// <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;
        }
コード例 #10
0
ファイル: MetaWeblog.cs プロジェクト: khaliyo/DiscuzNT
//实现文件上传

        public MediaObjectUrl newMediaObject(string blogid, string username, string password, MediaObject mediaObject)
        {
            int uid = ValidateUser(username, password);
            if (uid < 1)
                throw new XmlRpcFaultException(0, "用户不存在");

            string[] currentdate = DateTime.Now.ToString("yyyy-MM-dd").Split('-');
            string fileDatePath = currentdate[0] + "/" + currentdate[1] + "/" + currentdate[2] + "/";
            string sSavePath = Utils.GetMapPath(BaseConfigs.GetForumPath + "space/upload/" + ((FTPs.GetSpaceAttachInfo.Allowupload == 1 && FTPs.GetSpaceAttachInfo.Reservelocalattach == 0) ? "temp/" : fileDatePath));
            if (!Directory.Exists(sSavePath))
            {
                Utils.CreateDir(sSavePath);
            }

            Random random = new Random(unchecked((int)DateTime.Now.Ticks));
            string sFilename = (Environment.TickCount & int.MaxValue).ToString() + random.Next(1000, 9999).ToString() + System.IO.Path.GetExtension(mediaObject.name).ToLower();
            //判断sFilename的文件名称是否已存在于服务器上. 如存在, 则添加文件递增标识
            int file_append = 0;
            while (File.Exists(sSavePath + sFilename))
            {
                file_append++;
                sFilename = Path.GetFileNameWithoutExtension(mediaObject.name) + file_append.ToString() + Path.GetExtension(mediaObject.name).ToLower();
            }
            string fileExtName = Path.GetExtension(mediaObject.name).ToLower();
            fileExtName = fileExtName !="" ? fileExtName: ".invalidExtName";
            int groupid = Users.GetShortUserInfo(uid).Groupid;
            string attachextensions = GetAllowedExtensions(groupid);

            if ((attachextensions == null) || (attachextensions.ToLower().IndexOf(fileExtName.Remove(0, 1)) >= 0))
            {
                
                //上传图片文件
                if ((fileExtName == ".jpg") || (fileExtName == ".gif") || (fileExtName == ".png") || (fileExtName == ".jpeg"))
                {
                    try
                    {
                        int maxspacesize = UserGroups.GetUserGroupInfo(groupid).Maxspaceattachsize;
                        int currentspaceattachmentsize = DbProvider.GetInstance().GetSpaceAttachmentSizeByUserid(uid);
                        if ((maxspacesize - currentspaceattachmentsize - mediaObject.bits.Length) <= 0)  //个人空间的存储空间不足
                        {
                            throw new XmlRpcFaultException(101, "存储空间不足, 上传失败!");
                        }
                        else
                        {
                            FileStream newFile = new FileStream(sSavePath + sFilename, FileMode.Create);
                            newFile.Write(mediaObject.bits, 0, mediaObject.bits.Length);
                            newFile.Close();
                        }

                        string filename = "";
                        filename = GetAttachRootPath(fileDatePath);

                        //当支持FTP上传附件时,使用FTP上传远程附件,并在上传完成之后删除本地tempfilename文件
                        if (FTPs.GetSpaceAttachInfo.Allowupload == 1)
                        {
                            FTPs ftps = new FTPs();
                            ftps.UpLoadFile(filename.Replace(FTPs.GetSpaceAttachInfo.Remoteurl, ""), sSavePath + sFilename, FTPs.FTPUploadEnum.SpaceAttach);
                        }


                        filename = filename + sFilename;
                        //保存文件信息
                        SaveSpaceAttachment(mediaObject, uid, filename);

                        string permalink = filename;
                        if (!(FTPs.GetSpaceAttachInfo.Allowupload == 1))
                        {
                            permalink = "http://" + DNTRequest.GetCurrentFullHost() + filename;
                        }

                        MediaObjectUrl mediaObjectUrl = new MediaObjectUrl();
                        mediaObjectUrl.url = permalink;
                        return mediaObjectUrl;
                    }
                    catch 
                    {
                        File.Delete(sSavePath + sFilename);
                        throw new XmlRpcFaultException(102, "上传文件发生异常");
                    }
                }
                else //其它类型文件
                {

                    int maxspacesize = UserGroups.GetUserGroupInfo(groupid).Maxspaceattachsize;
                    int currentspaceattachmentsize = DbProvider.GetInstance().GetSpaceAttachmentSizeByUserid(uid);
                    if ((maxspacesize - currentspaceattachmentsize - mediaObject.bits.Length) <= 0)  //个人空间的存储空间不足
                    {
                        throw new XmlRpcFaultException(101, "存储空间不足, 上传失败!");
                    }
                    else
                    {
                        try
                        {
                            FileStream newFile = new FileStream(sSavePath + sFilename, FileMode.Create);
                            newFile.Write(mediaObject.bits, 0, mediaObject.bits.Length);
                            newFile.Close();

                            string filename = "";

                            filename = GetAttachRootPath(fileDatePath);
                            filename = filename + sFilename;
                            //保存文件信息
                            SaveSpaceAttachment(mediaObject, uid, filename);

                            //当支持FTP上传附件时,使用FTP上传远程附件,并在上传完成之后删除本地tempfilename文件
                            if (FTPs.GetSpaceAttachInfo.Allowupload == 1)
                            {
                                FTPs ftps = new FTPs();
                                ftps.UpLoadFile(GetAttachRootPath(fileDatePath).Replace(FTPs.GetSpaceAttachInfo.Remoteurl, ""), sSavePath + sFilename, FTPs.FTPUploadEnum.SpaceAttach);
                            }

                            string permalink = filename;
                            if (!(FTPs.GetSpaceAttachInfo.Allowupload == 1))
                            {
                                permalink = "http://" + DNTRequest.GetCurrentFullHost() + filename;
                            }
                            MediaObjectUrl mediaObjectUrl = new MediaObjectUrl();
                            mediaObjectUrl.url = permalink;
                            return mediaObjectUrl;
                        }
                        catch
                        {
                            File.Delete(sSavePath + sFilename);
                            throw new XmlRpcFaultException(102, "上传文件发生异常");
                        }
                    }
                }
            }
            return new MediaObjectUrl();
        }
コード例 #11
0
ファイル: uploadfile.ascx.cs プロジェクト: khaliyo/DiscuzNT
        private string StartUploadFile()
        {
            string sSavePath = "";

            if (ViewState["UploadDir"] != null)
                sSavePath = ViewState["UploadDir"].ToString();
            else
                sSavePath = Server.MapPath(BaseConfigs.GetForumPath + "space/upload/");

            if (filefield1.PostedFile != null)
            {
                HttpPostedFile myFile = filefield1.PostedFile;
                int nFileLen = myFile.ContentLength;
                if (nFileLen == 0)
                    return "";

                byte[] myData = new Byte[nFileLen];
                myFile.InputStream.Read(myData, 0, nFileLen);
                Random random = new Random(unchecked((int)DateTime.Now.Ticks));
                string sFilename = (Environment.TickCount & int.MaxValue).ToString() + random.Next(1000, 9999).ToString() + System.IO.Path.GetExtension(myFile.FileName).ToLower();

                //判断sFilename的文件名称是否已存在于服务器上. 如存在, 则添加文件递增标识
                int file_append = 0;
                while (File.Exists(sSavePath + sFilename))
                {
                    file_append++;
                    sFilename = Path.GetFileNameWithoutExtension(myFile.FileName) + file_append.ToString() + Path.GetExtension(myFile.FileName).ToLower();
                }

                string fileExtName = Path.GetExtension(myFile.FileName).ToLower();
                string relativeFilePath = ViewState["RelativeFilePath"].ToString().Trim();

                fileExtName = fileExtName !="" ? fileExtName: ".invalidExtName";

                if ((attachextensions == null) || (attachextensions.ToLower().IndexOf(fileExtName.Remove(0,1)) >= 0))
                {
                    //上传图片文件
                    if ((fileExtName == ".jpg") || (fileExtName == ".gif") || (fileExtName == ".png") || (fileExtName == ".jpeg"))
                    { 
                        try
                        {
                            AlbumPluginBase apb = AlbumPluginProvider.GetInstance();                        
                            //上传附件同时加入相册
                            if (albums.SelectedValue != "" && apb != null)
                            {
                                int maxphotosize = UserGroups.GetUserGroupInfo(_userinfo.Groupid).Maxspacephotosize;
                                int currentphotisize = apb.GetPhotoSizeByUserid(userid);
                                if ((maxphotosize - currentphotisize - nFileLen) <= 0)  //相册的存储空间不足
                                {
                                    HttpContext.Current.Response.Write("<script>alert('" + config.Albumname + "空间不足, 上传至相册失败!');</script>");
                                    HttpContext.Current.Response.End();
                                    return "";
                                }
                                else
                                {
                                    FileStream newFile = new FileStream(sSavePath + sFilename, FileMode.Create);
                                    newFile.Write(myData, 0, myData.Length);
                                    newFile.Close();

                                    string extension = Path.GetExtension(sSavePath + sFilename);
                                    Common.Thumbnail.MakeThumbnailImage(sSavePath + sFilename, (sSavePath + sFilename).Replace(extension, "_thumbnail" + extension), 150, 150);
                                    Common.Thumbnail.MakeSquareImage(sSavePath + sFilename, (sSavePath + sFilename).Replace(extension, "_square" + extension), 100);
                                    string sPath = relativeFilePath;
                                    if (sPath.StartsWith("/"))
                                        sPath = sPath.Substring(1, sPath.Length - 1);

                                    PhotoInfo photoinfo = new PhotoInfo();
                                    photoinfo.Filename = sPath + sFilename;
                                    photoinfo.Attachment = Path.GetFileName(filefield1.PostedFile.FileName);
                                    photoinfo.Filesize = nFileLen;
                                    photoinfo.Title = sFilename.Remove(sFilename.IndexOf("."), 1);
                                    photoinfo.Description = "";
                                    photoinfo.Albumid = Utils.StrToInt(albums.SelectedValue, 0);
                                    photoinfo.Userid = userid;
                                    photoinfo.Username = username;
                                    photoinfo.Views = 0;
                                    photoinfo.Commentstatus = 0;
                                    photoinfo.Tagstatus = 0;
                                    photoinfo.Comments = 0;
                                    photoinfo.IsAttachment = 1;
                                    Space.Data.DbProvider.GetInstance().AddSpacePhoto(photoinfo);
                                    AlbumInfo albumInfo = apb.GetAlbumInfo( Utils.StrToInt((albums.SelectedValue),0));
                                    albumInfo.Imgcount = Space.Data.DbProvider.GetInstance().GetSpacePhotoCountByAlbumId(Utils.StrToInt(albums.SelectedValue, 0));
                                    Space.Data.DbProvider.GetInstance().SaveSpaceAlbum(albumInfo);

                                    //当支持FTP上传附件时,使用FTP上传远程附件,并在上传完成之后删除本地tempfilename文件
                                    if (FTPs.GetSpaceAttachInfo.Allowupload == 1)
                                    {
                                        FTPs ftps = new FTPs();
                                        relativeFilePath = relativeFilePath.Replace(FTPs.GetSpaceAttachInfo.Remoteurl, "");
                                        ftps.UpLoadFile(relativeFilePath, sSavePath + sFilename, FTPs.FTPUploadEnum.SpaceAttach);
                                        ftps = new FTPs();
                                        ftps.UpLoadFile(relativeFilePath, (sSavePath + sFilename).Replace(extension, "_thumbnail" + extension), FTPs.FTPUploadEnum.SpaceAttach);
                                        ftps = new FTPs();
                                        ftps.UpLoadFile(relativeFilePath, (sSavePath + sFilename).Replace(extension, "_square" + extension), FTPs.FTPUploadEnum.SpaceAttach);
                                    }
                                }
                            }
                            else
                            {
                                int maxspacesize = UserGroups.GetUserGroupInfo(_userinfo.Groupid).Maxspaceattachsize;
                                int currentspaceattachmentsize = Space.Data.DbProvider.GetInstance().GetSpaceAttachmentSizeByUserid(userid);
                                if ((maxspacesize - currentspaceattachmentsize - nFileLen) <= 0)  //个人空间的存储空间不足
                                {
                                    HttpContext.Current.Response.Write("<script>alert('" + config.Spacename + "存储空间不足, 上传失败!');</script>");
                                    HttpContext.Current.Response.End();
                                    return "";
                                }
                                else
                                {
                                    FileStream newFile = new FileStream(sSavePath + sFilename, FileMode.Create);
                                    newFile.Write(myData, 0, myData.Length);
                                    newFile.Close();
                                }

                                //当支持FTP上传附件时,使用FTP上传远程附件,并在上传完成之后删除本地tempfilename文件
                                if (FTPs.GetSpaceAttachInfo.Allowupload == 1)
                                {
                                    FTPs ftps = new FTPs();
                                    ftps.UpLoadFile(relativeFilePath.Replace(FTPs.GetSpaceAttachInfo.Remoteurl, ""), sSavePath + sFilename, FTPs.FTPUploadEnum.SpaceAttach);
                                }     
                            }

                            InsertSapceAttachment(relativeFilePath + sFilename, myFile.ContentType, myData.Length, Path.GetFileName(myFile.FileName).ToLower());

                            return sFilename;
                        }
                        catch (ArgumentException errArgument)
                        {
                            File.Delete(sSavePath + sFilename);
                            HttpContext.Current.Response.Write("<script>alert('" + errArgument.Message + "!');</script>");
                            HttpContext.Current.Response.End();
                            return "";
                        }
                    }
                    else //其它类型文件
                    {  
                        int maxspacesize = UserGroups.GetUserGroupInfo(_userinfo.Groupid).Maxspaceattachsize;
                        int currentspaceattachmentsize = Space.Data.DbProvider.GetInstance().GetSpaceAttachmentSizeByUserid(userid);
                        if ((maxspacesize - currentspaceattachmentsize - nFileLen) <= 0)  //个人空间的存储空间不足
                        {
                            HttpContext.Current.Response.Write("<script>alert('" + config.Spacename + "存储空间不足, 上传失败!');</script>");
                            HttpContext.Current.Response.End();
                            return "";
                        }
                        else
                        {
                            try
                            {
                                myFile.SaveAs(sSavePath + sFilename);
                                InsertSapceAttachment(relativeFilePath + sFilename, myFile.ContentType, myData.Length, Path.GetFileName(myFile.FileName).ToLower());

                                //当支持FTP上传附件时,使用FTP上传远程附件,并在上传完成之后删除本地tempfilename文件
                                if (FTPs.GetSpaceAttachInfo.Allowupload == 1)
                                {
                                    FTPs ftps = new FTPs();
                                    ftps.UpLoadFile(relativeFilePath.Replace(FTPs.GetSpaceAttachInfo.Remoteurl, ""), sSavePath + sFilename, FTPs.FTPUploadEnum.SpaceAttach);
                                } 
                                return sFilename;
                            }
                            catch (ArgumentException errArgument)
                            {
                                File.Delete(sSavePath + sFilename);
                                HttpContext.Current.Response.Write("<script>alert('" + errArgument.Message + "!');</script>");
                                HttpContext.Current.Response.End();
                                return "";
                            }
                        }
                    }
                }
                else //当上传的附件类型无效时
                {
                    return "invalid_file";
                }
            }
            return "";
        }
コード例 #12
0
        /// <summary>
        /// 截取指定位置的图片信息
        /// </summary>
        /// <param name="filePathName"></param>
        /// <param name="point"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        private bool GrabImage(CredentialInfo creinfo, string filePathName, Point point, Size size)
        {
            if(!System.IO.File.Exists(filePathName))  return false;

            Image oldImage = System.Drawing.Image.FromFile(filePathName);

            if (size.Width > oldImage.Width || size.Height > oldImage.Height)
            {
                oldImage.Dispose();
                return false;
            }

            //用指定的大小和格式初始化 Bitmap 类的新实例
            Bitmap bitmap = new Bitmap(size.Width, size.Height, PixelFormat.Format32bppArgb);
            Color backColor = Color.Black;// bitmap.GetPixel(1, 1);
            bitmap.MakeTransparent(backColor);

            //从指定的 Image 对象创建新 Graphics 对象
            Graphics graphics = Graphics.FromImage(bitmap);
            // 0,0 是graphics的起始位置,也就是从原点开始画
            // new Rectangle是截取源图片的目标区域,用户只需要改变其中四个值即可
            graphics.DrawImage(oldImage /*是原图片*/, 0, 0, new Rectangle(point.X, point.Y, size.Width, size.Height), GraphicsUnit.Pixel);
            // 将Bitmap转化成Image
            Image image = Image.FromHbitmap(bitmap.GetHbitmap());

            ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
            ImageCodecInfo ici = null;
            foreach (ImageCodecInfo codec in codecs)
            {
                if (codec.MimeType.IndexOf("jpeg") > -1)
                    ici = codec;
            }
            EncoderParameters encoderParams = new EncoderParameters();
            long[] qualityParam = new long[1];
            qualityParam[0] = 100;
            EncoderParameter encoderParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, qualityParam);
            encoderParams.Param[0] = encoderParam;


            string uid = Avatars.FormatUid(creinfo.UserID.ToString());
            string avatarFileName = string.Format("{0}avatars/upload/{1}/{2}/{3}/{4}_avatar_",
               BaseConfigs.GetForumPath, uid.Substring(0, 3), uid.Substring(3, 2), uid.Substring(5, 2), uid.Substring(7, 2));
            avatarFileName = Utils.GetMapPath(avatarFileName);
            image.Save(avatarFileName + "large.jpg", ici, encoderParams);

            if (size.Width * 0.8 <= 130)//前台模版宽度
            {
                Thumbnail.MakeThumbnailImage(avatarFileName + "large.jpg", avatarFileName + "medium.jpg",
                          (int)(size.Width * 0.8),
                          (int)(size.Height * 0.8));
                Thumbnail.MakeThumbnailImage(avatarFileName + "large.jpg", avatarFileName + "small.jpg",
                          (int)(size.Width * 0.6),
                          (int)(size.Height * 0.6));
            }
            else
            {
                 Thumbnail.MakeThumbnailImage(avatarFileName + "large.jpg", avatarFileName + "medium.jpg",
                          (int)(size.Width * 0.5),
                          (int)(size.Height * 0.5));
                 Thumbnail.MakeThumbnailImage(avatarFileName + "large.jpg", avatarFileName + "small.jpg",
                          (int)(size.Width * 0.3),
                          (int)(size.Height * 0.3));
            }

            try
            {
                oldImage.Dispose();
                System.IO.File.Delete(filePathName);
            }
            catch { }

            //当支持FTP上传头像时,使用FTP上传远程头像
            if (FTPs.GetForumAvatarInfo.Allowupload == 1)
            {
                FTPs ftps = new FTPs();
                string ftpAvatarFileName = string.Format("/avatars/upload/{0}/{1}/{2}/",
                       uid.Substring(0, 3), uid.Substring(3, 2), uid.Substring(5, 2));
                ftps.UpLoadFile(ftpAvatarFileName, avatarFileName + "large.jpg", FTPs.FTPUploadEnum.ForumAvatar);
                ftps.UpLoadFile(ftpAvatarFileName, avatarFileName + "medium.jpg", FTPs.FTPUploadEnum.ForumAvatar);
                ftps.UpLoadFile(ftpAvatarFileName, avatarFileName + "small.jpg", FTPs.FTPUploadEnum.ForumAvatar);
            }
            return true;
        }
コード例 #13
0
ファイル: global_ajaxcall.aspx.cs プロジェクト: ichari/ichari
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!Page.IsPostBack)
     {
         int pertask = DNTRequest.GetInt("pertask", 0);
         int lastnumber = DNTRequest.GetInt("lastnumber", 0);
         int startvalue = DNTRequest.GetInt("startvalue", 0);
         int endvalue = DNTRequest.GetInt("endvalue", 0);
         string resultmessage = "";
         switch (Request.Params["opname"])
         {
             case "ReSetFourmTopicAPost":
                 AdminForumStats.ReSetFourmTopicAPost(pertask, ref lastnumber);
                 resultmessage = lastnumber.ToString();
                 break;
             case "ReSetUserDigestPosts":
                 AdminForumStats.ReSetUserDigestPosts(pertask, ref lastnumber);
                 resultmessage = lastnumber.ToString();
                 break;
             case "ReSetUserPosts":
                 AdminForumStats.ReSetUserPosts(pertask, ref lastnumber);
                 resultmessage = lastnumber.ToString();
                 break;
             case "ReSetTopicPosts":
                 AdminForumStats.ReSetTopicPosts(pertask, ref lastnumber);
                 resultmessage = lastnumber.ToString();
                 break;
             case "ReSetFourmTopicAPost_StartEnd":
                 AdminForumStats.ReSetFourmTopicAPost(startvalue, endvalue);
                 resultmessage = "1";
                 break;
             case "ReSetUserDigestPosts_StartEnd":
                 AdminForumStats.ReSetUserDigestPosts(startvalue, endvalue);
                 resultmessage = "1";
                 break;
             case "ReSetUserPosts_StartEnd":
                 AdminForumStats.ReSetUserPosts(startvalue, endvalue);
                 resultmessage = "1";
                 break;
             case "ReSetTopicPosts_StartEnd":
                 AdminForumStats.ReSetTopicPosts(startvalue, endvalue);
                 resultmessage = "1";
                 break;
             case "ftptest":
                 string serveraddress = DNTRequest.GetString("serveraddress");
                 string serverport = DNTRequest.GetString("serverport");
                 string username = DNTRequest.GetString("username");
                 string password = DNTRequest.GetString("password");
                 string timeout = DNTRequest.GetString("timeout");
                 string uploadpath = DNTRequest.GetString("uploadpath");
                 FTPs ftps = new FTPs();
                 string message = "";
                 bool ok = ftps.TestConnect(serveraddress, int.Parse(serverport), username, password, int.Parse(timeout), uploadpath, ref message);
                 if (ok)
                 {
                     resultmessage = "ok";
                 }
                 else
                 {
                     resultmessage = "远程附件设置测试出现错误!\n描述:" + message;
                 }
                 break;
             case "setapp":
                 string allowpassport = DNTRequest.GetString("allowpassport");
                 APIConfigInfo aci = APIConfigs.GetConfig();
                 aci.Enable = allowpassport == "1";
                 APIConfigs.SaveConfig(aci);
                 resultmessage = "ok";
                 break;
             
         }
         Response.Write(resultmessage);
         Response.ExpiresAbsolute = DateTime.Now.AddSeconds(-1);
         Response.Expires = -1;
         Response.End();
     }
 }