0

In PHP and JS, I am making a file upload progress indicator, how can I check the size of file 'being uploaded'. I know we can get the size before upload in JS and after uploaded in PHP, but how to get it while being uploaded.

Like every second, I want to send an Ajax call and see how many bytes uploaded.

phpMax
  • 149
  • 1
  • 10

1 Answers1

0

As far i know it isn't possible using plain old javascript. Even it isn't possible to access the file system in anyway.

Only way to do this is 'receiving' the file for whatever server processes, to count the amount of data transferred.

There is an alternative way(not recommended) that can help you:

<form name="a">
    <input type="file" name="b">
    <input type="button" name="c" value="SIZE" onClick="A();">
</form>

<script language="JavaScript">
    function A(){
        var oas = new ActiveXObject("Scripting.FileSystemObject");
        var d = document.a.b.value;
        var e = oas.getFile(d);
        var f = e.size;
        alert(f + " bytes");
    }
</script>
S M Iftakhairul
  • 1,120
  • 2
  • 19
  • 42