HTTP方式图片上传,文件下载
Code
for (int i = 0; i < iTotal; i++)
{
try
{
//取得上传文件信息,并替换其名称
HttpPostedFile file = context.Request.Files[i];
sFile = Path.GetFileName(file.FileName);
sFile = sFile.Substring(sFile.LastIndexOf("."));
string datatime = System.DateTime.Now.ToString("yyyyMMddHHmmssffff"); //为了防止重名,获得日期为文件名 年月日时分秒毫秒
sFile = datatime + sFile; //上传后文件的新名
//创建文件夹
string strDay = System.DateTime.Now.ToString("yyyyMM");
DirUrl = HttpContext.Current.Server.MapPath("~/img/" + strDay + "/");
if (!System.IO.Directory.Exists(DirUrl)) //检测文件夹是否存在,不存在则创建
System.IO.Directory.CreateDirectory(DirUrl);
_Url = "http://www.cnblogs.com/img/" + strDay + "/"; //
if (file.ContentLength > 0 || !string.IsNullOrEmpty(file.FileName))
{
//保存文件
file.SaveAs(DirUrl + sFile);
url = _Url + sFile;
reUrl = url;
if (context.Request.Form["Type"].ToUpper() != "NOWATER")
{
Solely.ImageWater sy = new Solely.ImageWater(url);
bool flag = sy.Watermark();
reUrl = sy.ThumbImage;
}
}
}
catch(Exception ex)
{
url = "error";
context.Response.Write("<script>window.parent.Finish('" + reUrl + "');</script>");
}
}
for (int i = 0; i < iTotal; i++)
{
try
{
//取得上传文件信息,并替换其名称
HttpPostedFile file = context.Request.Files[i];
sFile = Path.GetFileName(file.FileName);
sFile = sFile.Substring(sFile.LastIndexOf("."));
string datatime = System.DateTime.Now.ToString("yyyyMMddHHmmssffff"); //为了防止重名,获得日期为文件名 年月日时分秒毫秒
sFile = datatime + sFile; //上传后文件的新名
//创建文件夹
string strDay = System.DateTime.Now.ToString("yyyyMM");
DirUrl = HttpContext.Current.Server.MapPath("~/img/" + strDay + "/");
if (!System.IO.Directory.Exists(DirUrl)) //检测文件夹是否存在,不存在则创建
System.IO.Directory.CreateDirectory(DirUrl);
_Url = "http://www.cnblogs.com/img/" + strDay + "/"; //
if (file.ContentLength > 0 || !string.IsNullOrEmpty(file.FileName))
{
//保存文件
file.SaveAs(DirUrl + sFile);
url = _Url + sFile;
reUrl = url;
if (context.Request.Form["Type"].ToUpper() != "NOWATER")
{
Solely.ImageWater sy = new Solely.ImageWater(url);
bool flag = sy.Watermark();
reUrl = sy.ThumbImage;
}
}
}
catch(Exception ex)
{
url = "error";
context.Response.Write("<script>window.parent.Finish('" + reUrl + "');</script>");
}
}