示例#1
0
    public string imgLoad()
    {
        string imgUrl;

        if (Request.Files.Count > 0)
        {
            string type     = Request.Files[0].ContentType;
            string fileExt  = Path.GetExtension(Request.Files[0].FileName).ToLower();
            string fileFilt = ".gif|.jpg|.png|.jsp";
            if (fileFilt.IndexOf(fileExt) <= -1)
            {
                Response.Write("<script>alert('对不起,请上传图片!')</script>");
                return("");
            }
            else
            {
                fileName = Server.MapPath(_directory) + "\\" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + rnd.Next(10, 99).ToString() + fileExt;
                Request.Files[0].SaveAs(fileName);
                QiniuUpload qiniuload = new QiniuUpload();
                //获取图片名
                string[] sArray  = fileName.Split('\\');
                string   imgName = sArray[10];
                imgName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + rnd.Next(10, 99).ToString() + fileExt;
                imgUrl  = qiniuload.upLoadImg(fileName, imgName);
                //Response.Write("<script>alert('图片上传成功!')</script>");
                return(imgUrl);
            }
        }
        return("");
    }
示例#2
0
        void Application_Start(object sender, EventArgs e)
        {
            // Code that runs on application startup
            //AreaRegistration.RegisterAllAreas();

            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            LogHelper.LogConfig(Server.MapPath(@"~\App_Data\log4net.config"));
            DtoMapper.AutoMapper();

            QiniuUpload.Config();
        }
示例#3
0
        public object GetImageToken()
        {
            var         result = new XResult();
            QiniuUpload qiniu  = new QiniuUpload();

            if (string.IsNullOrEmpty(qiniu.Token))
            {
                result.Code    = 10000;
                result.Message = "获取Token失败";
            }
            result.Data = qiniu.Token;
            return(result);
        }
示例#4
0
        public ActionResult PostJoke(string joketitle, string jokecontent, int joketype, int jokecategory, HttpPostedFileBase jokeImgFile)
        {
            string content = "";

            if (joketype == 0)
            {
                content = jokecontent;
            }
            else if (joketype == 1)
            {
                //FileInfoHelper.GetFileName(jokeImgFile.FileName);
                //FileInfoHelper.GetFileExtend(jokeImgFile.FileName);
                string newName = FileInfoHelper.GetNewName(jokeImgFile.FileName);
                if (Request.IsLocal)
                {
                    newName = string.Format("local_{0}", newName);
                }
                else
                {
                    newName = string.Format("online_{0}", newName);
                }
                string uploadFolder = string.Format("{3}\\{0}\\{1}\\{2}", DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, JokeImgUpload);
                if (!Directory.Exists(uploadFolder))
                {
                    Directory.CreateDirectory(uploadFolder);
                }
                //
                jokeImgFile.SaveAs(uploadFolder + "\\" + newName);
                Thread.Sleep(1);
                string fileName = jokeImgFile.FileName;
                content = string.Format("{0}\\{1}\\{2}", DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day) + "\\" + newName;
                if (AppConfig.IsQiniuUpload > 0)
                {
                    bool updateResult = QiniuUpload.PutFile(newName, uploadFolder + "\\" + newName);
                }
            }

            T_Joke jokeinfo = new T_Joke()
            {
                AddDate      = DateTime.Now,
                Category     = jokecategory,
                CheckDate    = DateTime.Parse("1900-01-01"),
                CheckUserId  = 0,
                CommentCount = 0,
                Content      = content,
                HateCount    = 0,
                LikeCount    = 0,
                PostID       = user.UserId,
                State        = 0,
                Title        = joketitle,
                Type         = joketype
            };

            if (user.IsAdmin > 0)
            {
                jokeinfo.State       = 1;
                jokeinfo.CheckDate   = DateTime.Now;
                jokeinfo.CheckUserId = user.UserId;
            }
            int            jokeId     = jokeBusinessLogic.AddJoke(jokeinfo);
            PostJokeResult postResult = new PostJokeResult()
            {
                Success = jokeId > 0?true:false,
                Message = jokeId > 0?"发表成功":"发表失败"
            };

            TempData["PostResult"] = postResult;



            return(RedirectToAction("PostJokeResult"));
        }