2012-04-04 11 views
0

jqueryを使用してファイルサイズを測定するには、次のコードはFirefox、Chromeでうまく動作しますが、IE(7/8/9)では機能しません。いずれか IEASP.NETでjQueryを使用してアップロードしたファイルのサイズを測定

でファイルサイズを測定するために、どのように私を助ける
var fi = document.getElementById('loadfile'); 
var sizeInMB = fi.files[0].size; 
    sizeInMB = (sizeInMB/(1024 * 1024)); 
if (sizeInMB > 20) 
    alert("File size more than 20MB"); 
else 
    alert("File size less than 20MB"); 
+1

あなたはこの答えを見ましたか? http://stackoverflow.com/a/1440804/882630 – lukkea

+0

[jQueryでファイルサイズを見つける]の可能な複製(http://stackoverflow.com/questions/1440723/find-file-size-with-jquery) – Gray

+0

@Gray - 前のコメントの可能な複製! – lukkea

答えて

0

は、この方法を試すことができます:

<script runat="server"> 

    protected void UploadButton_Click(object sender, EventArgs e) 
    { 

     string savePath = @"c:\temp\uploads\"; 


     if (FileUpload1.HasFile) 
     {     
      // Get the size in bytes of the file to upload. 
      int fileSize = FileUpload1.PostedFile.ContentLength; 

      // Allow only files less than 2,100,000 bytes (approximately 2 MB) to be uploaded. 
      if (fileSize < 2100000) 
      { 

       // Append the name of the uploaded file to the path. 
       savePath += Server.HtmlEncode(FileUpload1.FileName); 


       FileUpload1.SaveAs(savePath); 


       UploadStatusLabel.Text = "Your file was uploaded successfully."; 
      } 
      else 
      { 

       UploadStatusLabel.Text = "Your file was not uploaded because " + 
             "it exceeds the 2 MB size limit."; 
      } 
     } 
     else 
     { 

      UploadStatusLabel.Text = "You did not specify a file to upload."; 
     } 
    } 
</script> 
関連する問題