if (Request.Files.Count > 0)
{
//这里只测试上传第一张图片file[0]
HttpPostedFile file0 = Request.Files[0];
string ext = file0.FileName.Substring(file0.FileName.LastIndexOf('.') + 1);//文件扩展名string[] fileTypeStr = { "jpg", "gif", "bmp", "png" };
if (fileTypeStr.Contains(ext))
{
file0.SaveAs(Server.MapPath("~/" + file0.FileName));//保存文件 }
else
{
Response.Write("图片格式不正确" + ext);
}
}
if (Request.Files.Count > 0)
{
//这里只测试上传第一张图片file[0]
HttpPostedFile file0 = Request.Files[0];
string contentType = file0.ContentType;//文件类型string[] fileTypeStr = { "image/gif","image/x-png","image/pjpeg","image/jpeg","image/bmp"};
if (fileTypeStr.Contains(contentType))
{
file0.SaveAs(Server.MapPath("~/" + file0.FileName));
}
else
{
Response.Write("图片格式不正确" + contentType);
}
}
if (Request.Files.Count > 0)
{
//这里只测试上传第一张图片file[0]
HttpPostedFile file0 = Request.Files[0];
//转换成byte,读取图片MIME类型 Stream stream;
//int contentLength = file0.ContentLength; //文件长度byte[] fileByte = newbyte[2];//contentLength,这里我们只读取文件长度的前两位用于判断就好了,这样速度比较快,剩下的也用不到。
stream = file0.InputStream;
stream.Read(fileByte, 0, 2);//contentLength,还是取前两位 stream.Close();
string fileFlag = "";
if (fileByte != null && fileByte.Length > 0)//图片数据是否为空 {
fileFlag = fileByte[0].ToString() + fileByte[1].ToString();
}
string[] fileTypeStr = { "255216", "7173", "6677", "13780" };//对应的图片格式jpg,gif,bmp,pngif (fileTypeStr.Contains(fileFlag))
{
file0.SaveAs(Server.MapPath("~/" + file0.FileName));
}
else
{
Response.Write("图片格式不正确:" + fileFlag);
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有