Lấy chiều cao và rộng của HttpPostedFileBase, get width Height HttpPostedFileBase

Thảo luận trong 'Lập trình web Asp.net' bắt đầu bởi seolagi, 25/11/20.

  1. seolagi
    Tham gia ngày:
    16/4/14
    Bài viết:
    1,028
    Đã được thích:
    80
    Điểm thành tích:
    48
    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ảm ơn đã xem bài:

    Lấy chiều cao và rộng của HttpPostedFileBase, get width Height HttpPostedFileBase

  2. admin
    Tham gia ngày:
    22/5/13
    Bài viết:
    4,895
    Đã được thích:
    1,198
    Điểm thành tích:
    113
    Giới tính:
    Nam
    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 
    0files.lengthi++) {
                    
    formdata.append(files[i].namefiles[i]);
                }
                if (
    files.length 0) {
                    $.
    ajax({
                        
    url'/Controller/Action',
                        
    type"POST",
                        
    contentTypefalse// Not to set any content header
                        
    processDatafalse// Not to process data
                        
    dataformdata,
                        
    asyncfalse,
                        
    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);
    }
    
     
    seolagi thích bài này.
  3. seolagi
    Tham gia ngày:
    16/4/14
    Bài viết:
    1,028
    Đã được thích:
    80
    Điểm thành tích:
    48
    E cảm ơn ạ, ad hướng dẫn rất chi tiết
     


Chủ để tương tự : Lấy chiều
Diễn đàn Tiêu đề Date
Lập trình web Asp.net Lấy Id Event OnClick Button trong Page_Load asp.net c# 24/10/18
Lập trình web Asp.net Get item value HashSet, lấy dữ liệu item HashSet<> c# asp.net MVC 8/9/18
Lập trình web Asp.net Lấy IP máy Client người dùng trong asp.net (C#) như thế nào 27/3/18
Lập trình web Asp.net Lấy toàn bộ thẻ src và <img /> của chuỗi html truyền vào trong asp.net 7/3/18
Lập trình web Asp.net Lấy lại đường dẫn URL truy cập trước đó trong asp.net 30/11/17