动态添加input type="file"
只能上传图片格式已判断请问:如何在上传时候判断上传的图片尺寸 例如不能超过100px*100px
 <asp:Button ID="btnEdit"  runat="server" Text="添加" OnClientClick="return checkImgs()" OnClick="btnEdit_Click" />
js或者后台cs实现

解决方案 »

  1.   

    目前后台的方法如下  HttpFileCollection files = HttpContext.Current.Request.Files;
            for (int iFile = 0; iFile < files.Count; iFile++)
            {
                ///'检查文件扩展名字
                HttpPostedFile postedFile = files[iFile];
              
                string fileName, fileExtension;
                fileName = System.IO.Path.GetFileName(postedFile.FileName);
                if (fileName != "")
                {
                    fileExtension = System.IO.Path.GetExtension(fileName);
                    //strMsg.Append("上传的文件类型:" + postedFile.ContentType.ToString() + "<br>");
                    //strMsg.Append("客户端文件地址:" + postedFile.FileName + "<br>");
                    //strMsg.Append("上传文件的文件名:" + fileName + "<br>");
                    //strMsg.Append("上传文件的扩展名:" + fileExtension + "<br><hr>");
                    /////'可根据扩展名字的不同保存到不同的文件夹
                    ///注意:可能要修改你的文件夹的匿名写入权限。
                    if (fileExtension != "JPG" || fileExtension != "GIF" || fileExtension != "PNG" || fileExtension != "BMP")
                    {
                        this.ClientScript.RegisterClientScriptBlock(this.GetType(), "ErrorMessage", "<script>alert('上传文件必须为图片格式!')</script>");
                        return;
                    }
                    string imgUrl = "/Admin/NewsImgs/" + fileName;                imgs += imgUrl + "|";
                   
                   
                    postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("~/Admin/NewsImgs/") + fileName);
                }
            }
      

  2.   

    檢查postedFile.ContentLength的大小
      

  3.   

    暈 看錯了
    試試這樣 System.Drawing.Image img = System.Drawing.Image.FromStream(this.FileUpload1.PostedFile.InputStream);
    img.Size.Height 
    img.Size.Width;
      

  4.   

    引用System.Drawing.DLL,把图片放到 BitMap 中去,然后取得大小。如果客户端可以先获得图片,在客户端判断是唯一符合现代的用户体验要求的解决方案。
      

  5.   

    判断图片大小
    function imgExceedSize(w, h) {
                if (!document.IUpload.picsrc.value == " ") {
                    if (picshow.width > w || picshow.height > h) {
                        alert("图像尺寸: " + picshow.width + "X " + picshow.height + "。\\n图像尺寸过大!你只能上传尺寸为   " + w + "× " + h + "的图像,请重新浏览图片! ");
                        return true;
                    } else {
                        return false;
                    }
                } else {
                    return true;
                }
            }
      

  6.   


    System.Drawing.Image image = System.Drawing.Image.FromStream(postedFile .InputStream);
    image.Width 
    image.Height