ajax上传图片文件
2021-03-05 03:26
标签:ssd file guid val asp formdata process pre oid HTML: Js: ASP.Net MVC 后台: ajax上传图片文件 标签:ssd file guid val asp formdata process pre oid 原文地址:https://www.cnblogs.com/licm/p/12910933.html
public void Process(string nickname, HttpPostedFileWrapper avator)
{
//将图片上传到 upload 文件夹下 (upload下,且按照时间存放图片)
string baseUrl = AppDomain.CurrentDomain.BaseDirectory + "upload\\";
int year = DateTime.Now.Year;
int month = DateTime.Now.Month;
int day = DateTime.Now.Day;
string dayUrl = baseUrl + year + "\\" + month + "\\" + day;
//判断是否存在年月份文件夹,如果不存在则创建
if (!Directory.Exists(dayUrl))
{
Directory.CreateDirectory(dayUrl);
}
//获取拓展名
string ext = System.IO.Path.GetExtension(avator.FileName);
//这里可进行判断是否为 合法的格式文件
//...
string avatorName = Guid.NewGuid().ToString();
avator.SaveAs(dayUrl + "\\" + avatorName + ext);
}