110,536
社区成员
发帖
与我相关
我的任务
分享
for (int i = 0; i < Files.Count; i++)
{
HttpPostedFile file = Files[i];
if (file.ContentLength > 0 && file.ContentType.IndexOf("image/") >= 0)
{
string fileNm = DateTime.Now.ToString("yyyyMMddHHmmss") + DateTime.Now.ToString("yyyy-MM-ddHHmmss") + ".gif";
fileName = ctx.Request.Params["File" + (i + 1) + "Name"] != null ?
ctx.Request.Params["File" + (i + 1) + "Name"] : "";
fileInfo = ctx.Request.Params["File" + (i + 1) + "Info"] != null ?
ctx.Request.Params["File" + (i + 1) + "Info"] : "";
filePath = dir + "/" + fileNm;
Image imgPhoto = Image.FromStream(file.InputStream, true);
Thread.Sleep(2000);
Bitmap bmPhoto = new Bitmap(imgPhoto.Width, imgPhoto.Height);
Graphics gbmPhoto = Graphics.FromImage(bmPhoto);
gbmPhoto.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
gbmPhoto.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
gbmPhoto.Clear(Color.Transparent);
gbmPhoto.DrawImage(imgPhoto, new Rectangle(0, 0, imgPhoto.Width, imgPhoto.Height), new Rectangle(0, 0, imgPhoto.Width, imgPhoto.Height), GraphicsUnit.Pixel);
bmPhoto.Save(map + "/" + dir + "/" + fileNm, ImageFormat.Gif);
imgPhoto.Dispose();
gbmPhoto.Dispose();
bmPhoto.Dispose();
int no = db.ExecuteSQL("insert into imgUpload values('" + fileName + "', '" + fileInfo + "', '" + filePath + "', '" + DateTime.Now.ToString("yyyy-MM-dd") + "')");
if (no < 0)
errmsg += "图片:" + fileName + "上传失败;";
}
}