-1

I faced an issue that while working on Drupal/PHP forms there was a requirement to check upload file size before uploading, and it was required to be done by using javascript or PHP.

Issue is PHP is a server based language, and cannot interact efficiently with the browser in a sense that this is a client side thing.

And if we see javascript, browser show different results and are inconsistant.

I need a solution which can be run on every browser.

Thanks in advance. I am waiting for a solution.

Please note that I need solution for HTML not for HTML5

Ata ul Mustafa
  • 1,172
  • 12
  • 18

1 Answers1

0

Check out the HTML5 File API, though older browsers won't be able to use it. Source Here.

    <input type="file" id="files" name="files[]" multiple />
<output id="list"></output>

<script>
  function handleFileSelect(evt) {
    var files = evt.target.files; // FileList object

    // files is a FileList of File objects. List some properties.
    var output = [];
    for (var i = 0, f; f = files[i]; i++) {
      output.push('<li><strong>', escape(f.name), '</strong> (', f.type || 'n/a', ') - ',
                  f.size, ' bytes, last modified: ',
                  f.lastModifiedDate ? f.lastModifiedDate.toLocaleDateString() : 'n/a',
                  '</li>');
    }
    document.getElementById('list').innerHTML = '<ul>' + output.join('') + '</ul>';
  }

  document.getElementById('files').addEventListener('change', handleFileSelect, false);
</script>
Ben Fortune
  • 31,623
  • 10
  • 79
  • 80