2014-02-17 3 views
-1
나는 그것보다 더 큰 500킬로바이트 예 경보()

GET 크기

<img src="@Model.Value" width="95" height="80" id="down-load" data-id="@Model.Key" data upload="@Url.Action("AddPreview", "Images")" />

(function ($) { 
$("[data-id]").each(function() { 
    var $this = $(this); 
    $($this).upload({ 
     name: 'attachments', 
     action: $this.data("upload"), 
     enctype: 'multipart/form-data', 
     params: {}, 
     autoSubmit: true, 
     onSubmit: function() { }, 
     onSelect: function() { 
     var size = $('#down-load')[0].files[0].size;//do not work 

     }, 
     onComplete: function (e) { 
      if (e.charAt(0) != '[') { 
       $.fn.showUserActionNotification(e, true); 
       return; 
      } 

      var data = JSON.parse(e); 
      if (data[0].Error) { 
       $.fn.showUserActionNotification(data[0].Error, true); 
      } 
      else if (data[0].Preview) { 
       $this.attr("src", data[0].Preview); 
      } 
     } 
    }); 

    $this.parent().find("input").css("cursor", "pointer"); 
}); 
})(jQuery); 

내가 그것을 확인하는 기능 onSelect를에 크기를 얻으려면 위해 줄 경우 파일을 검사 할

내보기 에 큰 시체가 나를 도울 수 있습니까?

+1

가능한 중복이 여기에 있습니다 : http://stackoverflow.com/questions/1601455/check-file-input-size-with-jquery/3937404#3937404 – Pavlo

+0

$ ('# down-load'). files [0] .size – Pavlo

+0

이 함수에는 파일이 없습니다. – user246340

답변

0

나는 기능

var imageSize = function (e) { 
return $.map(e.files, function (file) { 
    var name = file.name; 
    var size = file.size; 

    if (size > 512000) { 
     var alert = $(".valid-size-goods").text(name + ": " + (size/1024).toFixed(2) + " kb"); 
     alert.dialog({ 
      title: alert.attr("dlgTitle"), 
      modal: true, 
      resizable: false, 
      buttons: [{ text: alert.attr("btn"), click: function() { $(this).dialog("close"); } }] 
     }); return false; 
    } 
    return true; 
}); 

에게}했을;

및 onSelect를에 넣어 : imageSize (e)는