2023年6月21日发(作者:)

mysql批量上传相⽚_将图⽚写进数据库(上传多张图⽚)protected void btnUpload_Click(object sender, EventArgs e){Stream imgStream;int imgLen;string imgname_value;string imgcontenttype;string imguploadedname;string imgExt;string ErrMessage="";int AlbumID = 32(());string Caption="";leCollection files = ;int ifile;for (ifile = 0; ifile < ; ifile++){if (files[ifile].FileName != ""){imgLen = files[ifile].ContentLength;if (imgLen / 1024 > 1024) //单个⽂件不能⼤于1024K{ErrMessage += "图⽚上传不能⼤于1024K";}imgExt = ension(files[ifile].FileName).ToUpper().ToString(); //扩展名: 如: .jpg .gifif (imgExt != ".JPG" && imgExt != ".GIF"){ErrMessage += "图⽚格式不对,只能是jpg或gif格式";}}}if (ErrMessage != ""){=ErrMessage;return;}else{try{for (ifile = 0; ifile < ; ifile++){if (files[ifile].FileName != ""){// FileUpload fu=(FileUpload)ntrol("FileUpload" + ng());imgLen = files[ifile].ContentLength;byte[] imgbinarydata = new byte[imgLen];imgStream = files[ifile].InputStream;int n = (imgbinarydata, 0, imgLen);imgcontenttype = files[ifile].ContentType; //mime类型 ⽐如:image/pjpegif (dPhoto(AlbumID, imgbinarydata)){ = "图⽚添加成功";}else{ = "图⽚上传失败,请检查图⽚是否合法";}}}}catch (Exception ex){(ng());}}public static bool testAddPhoto(int AlbumID, byte[] BytesOriginal){using (SqlConnection con = Con()){using (SqlCommand cmd = new SqlCommand("sp_testAddPhoto", con)){dType = Procedure;(new SqlParameter("@AlbumID", AlbumID));(new SqlParameter("@Photo",BytesOriginal));try{();eNonQuery();return true;}catch{return false;}}}}

2023年6月21日发(作者:)

mysql批量上传相⽚_将图⽚写进数据库(上传多张图⽚)protected void btnUpload_Click(object sender, EventArgs e){Stream imgStream;int imgLen;string imgname_value;string imgcontenttype;string imguploadedname;string imgExt;string ErrMessage="";int AlbumID = 32(());string Caption="";leCollection files = ;int ifile;for (ifile = 0; ifile < ; ifile++){if (files[ifile].FileName != ""){imgLen = files[ifile].ContentLength;if (imgLen / 1024 > 1024) //单个⽂件不能⼤于1024K{ErrMessage += "图⽚上传不能⼤于1024K";}imgExt = ension(files[ifile].FileName).ToUpper().ToString(); //扩展名: 如: .jpg .gifif (imgExt != ".JPG" && imgExt != ".GIF"){ErrMessage += "图⽚格式不对,只能是jpg或gif格式";}}}if (ErrMessage != ""){=ErrMessage;return;}else{try{for (ifile = 0; ifile < ; ifile++){if (files[ifile].FileName != ""){// FileUpload fu=(FileUpload)ntrol("FileUpload" + ng());imgLen = files[ifile].ContentLength;byte[] imgbinarydata = new byte[imgLen];imgStream = files[ifile].InputStream;int n = (imgbinarydata, 0, imgLen);imgcontenttype = files[ifile].ContentType; //mime类型 ⽐如:image/pjpegif (dPhoto(AlbumID, imgbinarydata)){ = "图⽚添加成功";}else{ = "图⽚上传失败,请检查图⽚是否合法";}}}}catch (Exception ex){(ng());}}public static bool testAddPhoto(int AlbumID, byte[] BytesOriginal){using (SqlConnection con = Con()){using (SqlCommand cmd = new SqlCommand("sp_testAddPhoto", con)){dType = Procedure;(new SqlParameter("@AlbumID", AlbumID));(new SqlParameter("@Photo",BytesOriginal));try{();eNonQuery();return true;}catch{return false;}}}}