0

How to measure file size using jquery,the following code works fine in firefox,chrome but it is not work in IE (7/8/9). Can any one help me how to measure file size in IE

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");
4

1 回答 1

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>
于 2012-04-04T11:55:57.187 回答