コード例 #1
0
        private string SaveFile(HttpPostedFileBase file, int id)
        {
            string ext = Path.GetExtension(file.FileName).ToLower();

            if (!GlobVars.ValidImages.Contains(ext))
            {
                return(null);
            }

            string newName = id + "_" + AppFunc.GetUniqName() + ext;

            var savePath = Server.MapPath(GlobVars.ContentPath + "/players/");

            var di = new DirectoryInfo(savePath);

            if (!di.Exists)
            {
                di.Create();
            }

            // start security checking
            byte[] imgData;
            using (var reader = new BinaryReader(file.InputStream))
            {
                imgData = reader.ReadBytes(file.ContentLength);
            }
            System.IO.File.WriteAllBytes(savePath + newName, imgData);
            return(newName);
        }