请教我这个上传图片的程序判断文件大小时出了什么问题?
在程序里做了文件后缀名(jpg)和文件大小(100k)的过滤,可是当文件比较大,如几十M的时候,却直接报了错,过滤没起作用,各位帮看看是怎么回事?谢谢!fileupload控件名是'FileUpload_photo'
程序代码:
protected void Button1_Click(object sender, EventArgs e) { bool fileOK = false; string uppath = Server.MapPath("~/Stu_photo/"); if (this.FileUpload_photo.HasFile) { string fileException = (FileUpload_photo.FileName).ToLower(); if (fileException == ".jpg") //判断后缀名是否为jpg,并置标志位fileOK fileOK = true; } if (fileOK) { // 判断文件类型标识是否为真 if (this.FileUpload_photo.PostedFile.ContentLength / 1024 < 100) { // 判断文件大小是否超过100k try { this.FileUpload_photo.SaveAs(uppath + FileUpload_photo.FileName); this.Label1.Text = "上传完毕"; } catch (Exception ee) { this.Label1.Text = "出错了"; } } else { this.Label1.Text="文件超过100k了"; } } else { this.Label1.Text = "不是jpg图片"; } }