validating the filesize before upload(question)

Discussion in 'Programming' started by cris02, May 29, 2007.

  1. #1
    Hello,

    i want to ask how can i detect the filesize before i upload to server. i have here an example i found it on the net. but the problem, it detects only the size of an image file, what i need is to validate any files specially audio files. If you have any idea pls help.. thanks
    <head>
    <script type="text/javascript">
    function showSize(f) {
    if ((new Image()).fileSize) {
    var img = new Image();
    img.onload = imgOnload;
    img.onerror = imgOnerror;
    img.src = f.elements['myFile'].value;
    }
    }
    function imgOnload() {
    if (this.fileSize) {
    var size = this.fileSize;
    if (size > 1024) {
    size = Math.round((size / 1024) * 100) / 100;
    }
    document.write(
    'The file is ' + size +
    (this.fileSize > 1024 ? ' kilobytes' : ' bytes') +
    ' in size.'
    );
    }
    }
    function imgOnerror() {
    alert('The file is not an image or did not load.');
    }
    </script>
    </head>
    <body>
    <form name="myForm">
    <input type="file" name="myFile" onchange="showSize(this.form);">
    </form>
    
    Code (markup):

     
    cris02, May 29, 2007 IP
  2. wing

    wing Active Member

    Messages:
    210
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    58
  3. cris02

    cris02 Member

    Messages:
    55
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    cris02, Jun 5, 2007 IP