只允许上传 GIF JPG类型的文件 我在本地调试的时候是好的,但是放到服务器上就出现这个问题,都上传的同一张图片
解决方案 »
- 看这个效果,sql注入
- 一个人想做个系统,大家进来帮忙指导下!
- 如何获取GridView的行,然后循环执行。
- 欢迎大家来提意见
- 用JS能否获取gridview控件查询到的数据中的主键值,循环获取?
- 求个解决思路关于树的。。。
- 急~~~~ 请问为什么我在DataGrid中使用了模版列来做对DataGrid直接进行编辑 为什么他读出来的数据不是我修改的数据而是原来数据库的呢
- C#编写倒计时程序
- sql还是读不出数据?菜鸟问题
- .net 中的编程相结合问题
- VIEW与Controllers多层文件夹时,Controllers如何定向VIEW
- 如何让Attributes.Add在postBack后依然存在
//取得文件名(不含路径) char[] splitChar = { }; string[] FilenameArray = hpf.FileName.Split(splitChar); string Filename = FilenameArray[FilenameArray.Length - 1].ToLower(); if (hpf.FileName.Length < 1)
{ Response.Write("请选择您要上传的图片文件"); return; } if (hpf.ContentType != "image/pjpeg" && hpf.ContentType != "image/gif")
{ Response.Write("只允许上传 GIF JPG类型的文件"); return; } else
{ System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append(DateTime.Now.Year.ToString()); sb.Append(DateTime.Now.Month.ToString()); sb.Append(DateTime.Now.Day.ToString()); sb.Append(DateTime.Now.Hour.ToString()); sb.Append(DateTime.Now.Minute.ToString()); sb.Append(DateTime.Now.Second.ToString()); if (Filename.ToLower().EndsWith("gif"))
{ sb.Append(".gif"); } else if (Filename.ToLower().EndsWith("jpg"))
{ sb.Append(".jpg"); } else if (Filename.ToLower().EndsWith("jpeg"))
{ sb.Append(".jpeg"); } Filename = sb.ToString(); } // 保存图片到服务器上 try
{ hpf.SaveAs(Server.MapPath("\\") + "/newImage/" + Filename); string BigPic = "/newImage/" + Filename;
model.ybcs_SamllPic = BigPic; } catch (Exception ee)
{ Response.Write("上传图片失败,原因" + ee.Message); return; } // 生成缩略图 //原始图片名称 string originalFilename = hpf.FileName; //生成的高质量图片名称 string strFile = Server.MapPath("/newImage/Small_" + Filename);
string small_image = "/newImage/Small_" + Filename; model.ybcs_spPic = small_image;
//从文件取得图片对象 System.Drawing.Image image = System.Drawing.Image.FromStream(hpf.InputStream, true); Double Width = Double.Parse(TextBox26.Text.Trim()); Double Height = Double.Parse(TextBox27.Text.Trim()); System.Double NewWidth, NewHeight; if (image.Width > image.Height)
{ NewWidth = Width; NewHeight = image.Height * (NewWidth / image.Width); } else
{ NewHeight = Height; NewWidth = (NewHeight / image.Height) * image.Width; } if (NewWidth > Width)
{ NewWidth = Width; } if (NewHeight > Height)
{ NewHeight = Height; } System.Drawing.Size size = new Size((int)NewWidth, (int)NewHeight); // 图片大小 System.Drawing.Image bitmap = new System.Drawing.Bitmap(size.Width, size.Height); //新建bmp图片 System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap); //新建画板 graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; //设置高质量插值法 graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; //设置高质量,低速度呈现平滑程度 graphics.Clear(Color.White); //清空画布 //在指定位置画图 graphics.DrawImage(image, new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), new System.Drawing.Rectangle(0, 0, image.Width, image.Height), System.Drawing.GraphicsUnit.Pixel); //文字水印 System.Drawing.Graphics textGraphics = System.Drawing.Graphics.FromImage(bitmap); System.Drawing.Font font = new Font("宋体", 10); System.Drawing.Brush brush = new SolidBrush(Color.Black); textGraphics.DrawString(TextBox28.Text.Trim(), font, brush, 10, 10); textGraphics.Dispose();
try
{ bitmap.Save(strFile, System.Drawing.Imaging.ImageFormat.Jpeg); } catch (Exception ex)
{ Response.Write("保存缩略图失败:" + ex.Message); } graphics.Dispose(); image.Dispose(); bitmap.Dispose();
protected void Button2_Click(object sender, EventArgs e)
{
string extend=this.fileup.FileName.Substring(this.fileup.FileName.LastIndexOf("."));//取出上传文件的后缀名
if (extend.ToLower() == ".gif" || extend.ToLower() == ".jpg")
{
上传后的处理
}
else
{
ClientScript.RegisterStartupScript(this.GetType(),"tet","alert('请确定上传图片类型是否正确')",true);
} }
if (hpf.ContentType != "image/pjpeg" && hpf.ContentType != "image/gif" && hpf.ContentType != "image / jpeg") 多加了判断
{
//
}
else{
Response.Write("只允许上传 GIF JPG类型的文件");
return;
}不应该是这么写吗??