上传大小2张图片
protected void submit_Click(object sender, EventArgs e)
{
string Status = "";
string bigimage = "";
string smallimage = "";
bool status;
if (fileUpload.HasFile)
{
// 设置上传目录全路径
string path = "~/UploadFiles/images/";
string uploadPath = Server.MapPath("~/UploadFiles/images/");
//图片名称
string imgName = DateTime.Now.ToString("yyyyMMddhhmmss");
string[] resArr = Tu_BLL.UploadImg(uploadPath, fileUpload, imgName,path);
Status = resArr.GetValue(0).ToString();
bigimage = resArr.GetValue(1).ToString();
//smallimage = resArr.GetValue(1).ToString();
}
if (fileUpload1.HasFile)
{
// 设置上传目录全路径
string path = "~/UploadFiles/images/";
string uploadPath = Server.MapPath("~/UploadFiles/images/");
//图片名称
string imgName = DateTime.Now.ToString("yyyyMMddhh");
string[] resArr = Tu_BLL.UploadImg(uploadPath, fileUpload, imgName, path);
Status = resArr.GetValue(0).ToString();
//bigimage = resArr.GetValue(1).ToString();
smallimage = resArr.GetValue(1).ToString();
}
if (Request["id"] != "0")
{
string oldimageSourceA = Server.MapPath(Tu_BLL.imageSelectForID(int.Parse(Request["id"]))[0].bigimage);
string oldimageSourceB = Server.MapPath(Tu_BLL.imageSelectForID(int.Parse(Request["id"]))[0].smallimage);
if (bigimage == "")
{
bigimage = Tu_BLL.imageSelectForID(int.Parse(Request["id"]))[0].bigimage;
}
if (smallimage == "")
{
smallimage = Tu_BLL.imageSelectForID(int.Parse(Request["id"]))[0].smallimage;
}
else
{
Tu_BLL.DeleteFile(oldimageSourceA);
Tu_BLL.DeleteFile(oldimageSourceB);
}
status = Tu_BLL.UpdateImg(bigimage, smallimage, title.Text, int.Parse(Request["id"]));
}
else
{
status = Tu_BLL.ImageListInsertB(int.Parse(Request["uid"]), bigimage, smallimage, title.Text);
}
if (status) { Server.Transfer("page.aspx?uid=" + Request["uid"]); }
}
}
}
------解决方案--------------------
/// <summary>
/// 缩小图片
/// </summary>
/// <param name="strOldPic">源图文件名(包括路径)</param>
/// <param name="strNewPic">缩小后保存为文件名(包括路径)</param>
/// <param name="intWidth">缩小至宽度</param>
/// <param name="intHeight">缩小至高度</param>
public void SmallPic(string strOldPic, string strNewPic, int intWidth, int intHeight)
{
<