Exemplo n.º 1
0
        private string SaveFileToDisk(HttpPostedFileBase fileData, string folderPath)
        {
            var folderDate = DateTime.Now.ToString("yyyy/MM/dd");
            var folder     = "~/images/" + folderPath + "/" + folderDate;
            var result     = "";

            if (fileData.ContentLength <= 4000 * 1024 && HtmlHelpers.CheckFileExt(Path.GetExtension(fileData.FileName), "jpg|png|gif|jpeg") && HtmlHelpers.IsImage(fileData))
            {
                HtmlHelpers.CreateFolder(Server.MapPath(folder));

                var randomName = DateTime.Now.ToFileTimeUtc() + Path.GetExtension(fileData.FileName);

                var fileName = Server.MapPath(Path.Combine(folder, randomName));

                Resize(fileData, 1200, 900, Path.Combine(folder, fileName));
                result = folderDate + "/" + randomName;
            }
            return(result);
        }