sql field image
长度:自定义,1为一个字节,看你要上传多大的照片,长度就给多少。
file类型的input,转成byte[]
HttpPostedFile upFile = filePhoto.PostedFile;
int fileLength = upFile.ContentLength;
if (fileLength > 0)
{
Byte[] FileByteArray = new Byte[fileLength];
Stream StreamObject = upFile.InputStream;
StreamObject.Read(FileByteArray, 0, fileLength);
model.FPhoto = FileByteArray;
}
读取
View Code
SqlDataReader dr = xxxx.ExecuteReader(sql) as SqlDataReader;
if (dr.Read())
{
return (byte[])dr[0];
}
显示
View Code
context.Response.ContentType = "image/jpeg/gif/x-png";
context.Response.Cache.SetCacheability(HttpCacheability.Public);
context.Response.BufferOutput = false;
int personnelId = WRequest.GetInt("id");
HR.Dao.Personnel.PersonnelDao bll = new Dao.Personnel.PersonnelDao();
byte[] file = (Byte[])bll.GetUserImage(personnelId); //把图片信息取出来
context.Response.BinaryWrite(file);