我批量传图的时候 第一张图和第二张图总是一样的 但有时候还不一样 真晕 大家帮我看看 //默认上传文件夹
string defaultfolder = "../UploadPhotos/";
HttpFileCollection files = HttpContext.Current.Request.Files;
string[] arrShowLine = new string[2];
for (int i = 0; i < files.Count; i++)
{
HttpPostedFile postedfile = files[i];
if (postedfile.ContentLength > 0)
{
//上传
arrShowLine[i] = "UploadPhotos/" + Upload.file_Upload(postedfile, defaultfolder, this);
Response.Write("<script language=javascript>alert('图片传送成功!');</script>"); }
else {
arrShowLine[i] ="";
} } 这是上传累upload的方法 public static string file_Upload(HttpPostedFile postedFile, string uploadurl,Page page)
{
//获取文件扩展名
string filename = Path.GetFileName(postedFile.FileName);
string fileextension = Path.GetExtension(filename);
int filesize = postedFile.ContentLength;
//验证
string checkfile = CheckFile(filename, fileextension, filesize);
//文件安全性验证
// if (IsAllowedExtension(postedFile)){
if (checkfile == "")
{
//产生随机数
Random rd = new Random();
int valationNo = 10 + rd.Next(99);
//得到系统时间并加上随机数以便生成上传图片名称
string suiji = valationNo.ToString();
string uploadfiletime = DateTime.Now.ToString("yyyyMMddHHmmss") + suiji;
string newuploadfilename = uploadfiletime + fileextension;
//开始上传
postedFile.SaveAs(HttpContext.Current.Request.MapPath(uploadurl) + newuploadfilename);
return newuploadfilename;
}
else
{
page.Response.Redirect("error.aspx?error=" + checkfile);
}
return "";
}
string defaultfolder = "../UploadPhotos/";
HttpFileCollection files = HttpContext.Current.Request.Files;
string[] arrShowLine = new string[2];
for (int i = 0; i < files.Count; i++)
{
HttpPostedFile postedfile = files[i];
if (postedfile.ContentLength > 0)
{
//上传
arrShowLine[i] = "UploadPhotos/" + Upload.file_Upload(postedfile, defaultfolder, this);
Response.Write("<script language=javascript>alert('图片传送成功!');</script>"); }
else {
arrShowLine[i] ="";
} } 这是上传累upload的方法 public static string file_Upload(HttpPostedFile postedFile, string uploadurl,Page page)
{
//获取文件扩展名
string filename = Path.GetFileName(postedFile.FileName);
string fileextension = Path.GetExtension(filename);
int filesize = postedFile.ContentLength;
//验证
string checkfile = CheckFile(filename, fileextension, filesize);
//文件安全性验证
// if (IsAllowedExtension(postedFile)){
if (checkfile == "")
{
//产生随机数
Random rd = new Random();
int valationNo = 10 + rd.Next(99);
//得到系统时间并加上随机数以便生成上传图片名称
string suiji = valationNo.ToString();
string uploadfiletime = DateTime.Now.ToString("yyyyMMddHHmmss") + suiji;
string newuploadfilename = uploadfiletime + fileextension;
//开始上传
postedFile.SaveAs(HttpContext.Current.Request.MapPath(uploadurl) + newuploadfilename);
return newuploadfilename;
}
else
{
page.Response.Redirect("error.aspx?error=" + checkfile);
}
return "";
}
//默认上传文件夹
string defaultfolder = "../UploadPhotos/";
HttpFileCollection files = HttpContext.Current.Request.Files;
string[] arrShowLine = new string[2];
for (int i = 0; i < files.Count; i++)
{
HttpPostedFile postedfile = files[i];
if (postedfile[i].ContentLength > 0)
{
//上传
arrShowLine[i] = "UploadPhotos/" + Upload.file_Upload(postedfile, defaultfolder, this);
Response.Write("<script language=javascript>alert('图片传送成功!');</script>"); }
else {
arrShowLine[i] ="";
} }