- 1context.Response.ContentType ="text/html";
- 2
- 3 //拿到上传的文件
- 4HttpPostedFile file = context.Request.Files["imgFile"];
- 5
- 6 //后台也要校验
- 7 stringext = file.FileName.Substring(file.FileName.LastIndexOf("."));
- 8
- 9 if(!(ext ==".jpg"|| ext ==".jpeg"|| ext ==".png"|| ext ==".gif"))
- 10 {
- 11 //不是图片的时候
- 12context.Response.Write("shit");
- 13 context.Response.End();
- 14
- 15
- 16 }
- 17 else
- 18 {
- 19 stringpath ="/Upload/"+ Guid.NewGuid() + file.FileName;
- 20
- 21 file.SaveAs(context.Request.MapPath(path));
- 22
- 23 stringstr =string.Format("<html><head></head><body><img src='{0}'/></body></html>", path);
- 24
- 25 context.Response.Write(str);
- 26}
来源: http://www.bubuko.com/infodetail-2031918.html