Cho mình xin code lấy chiều cao và rộng của HttpPostedFileBase như thế nào vậy?, get width Height HttpPostedFileBase. Mình truyền HttpPostedFileBase từ javascript bằng formdata.append qua c# thông qua ajax ý. Trong code mình gọi ra bằng: HttpFileCollectionBase files = Request.Files, sau đó HttpPostedFileBase file = files để lấy file.
Của bạn đây nhé: CODE HTML PHP: <input id="fileuploadpicture" type="file" name="fileuploadpicture" multiple /><input type="button" class="btnUploadImg" name="upload" value="Tải lên" /><script> var formdata = new FormData(); //FormData object $(document).ready(function () { $(".btnUploadImg").click(function () { var fileUpload = $("#fileuploadpicture").get(0); var files = fileUpload.files; var formdata = new FormData(); for (var i = 0; i < files.length; i++) { formdata.append(files[i].name, files[i]); } if (files.length > 0) { $.ajax({ url: '/Controller/Action', type: "POST", contentType: false, // Not to set any content header processData: false, // Not to process data data: formdata, async: false, success: function (result) { alert(result); }, error: function (err) { alert(err.statusText); } }); } else { alert("Vui lòng chọn ảnh"); } }); });</script> CODE C# Mã: [HttpPost] public ActionResult UploadFiles() { HttpFileCollectionBase files = Request.Files; if (files != null && files.Count > 0) { for (int i = 0; i < files.Count; i++) { HttpPostedFileBase file = files[i]; var imgInfo = System.Drawing.Image.FromStream(file.InputStream, true, true); int wImgFile = imgInfo.Width; } } return Json("Tải lên thành công", JsonRequestBehavior.AllowGet); }