is it possible to have an progress bar depicting the progress of a file being uploaded through php?

haven't been able to find anything yet

thanks 🙂

    No.

    ...because php doesn't know about a file upload untill it's all the way uploaded. There are ways to do this client-side but even those are kinda weak. The best idea--with css or javascript...use "onClick()" to have the form disappear and in it's place some kind of animated gif or flash movie that says something like .."uploading..." or the like...

    Good luck..

      Sorry man, the answer is definately NO!
      The reason is basically caused your browser (client Side). The standard browser isn't smart enough to keep track of the uploading process.

      However, you could always use ActiveX or Java to code the client side to be more intelligent. Some commercial product is at ASPUpload.com. Not sure if it support PHP, but do check it out.

      Cheers

        Hey quit picking on the client! the server doesn't know anything about the upload either. ( at least not untill it's done )

        Plus, the browser DOES know about the file upload but clientside languages , for security reasons have limited access to information about the filesystem and state. Unless of course, you use active X like you mentioned which is a a security nightmare.

          Humm, just a question, can't it be done by using flush command? Like, first you retreive the size of the file, then you estimate the connection speed (dont ask me how-to) with that you can have a aprox. time upload, so you could use the flush command + css an Javascripts to change the status of a progress bar.

          Just thought on that ...

            You can't retrieve the size of the file until the upload is complete.

              vccarvalho, your idea is very interesting
              I've never seen any sites using this way but it sure sounds good! Let me know if anyone actually tried it.

                a month later

                It is possible to show a real progess bar.
                I've done it.

                The only problem is that u must have ur own server to do this. Cause by default php can't.

                U have to modify the file rfc1867.c of the php distribution source to write uploaded file information in a temporary file (information such as : time of upload, temporary filename, real name, length, domain...).

                So, when ur form is submitted, it will have to open a popup that will search information about the file in the temporary file generated by rfc1867.c

                And then it is simple to show a real progress bar !!!

                Now it is a little difficult to implement but maybe someone will make a php extension to do it ? maybe me ?


                If u have any question about this trick, send me an email : contact at pcapc dot com

                  17 days later

                  Hi LoVePaRaD

                  This is exactly what I searched for. Did you managed to write a php extension for that? 🙂 I am very interested!

                  Regards

                  Heady

                    hey!! no mr. no's!! the glass is half full eh??!!

                    what if you displayed an animated gif that showed a 'loading' progess bar ...

                    but in the php script, .. make it print a meta refresh after the upload is complete!

                    <?
                    if( upload function here )
                    {
                      echo "<meta refresh ... ";
                    }
                    ?>
                    

                      i think you have to understand though that a loading progress bar is not simply an animated gif - it's a bar that, unsurprisingly, tells you how much of the uploading process is complete. So unless you can tie your animated gif to the connection speed, file size etc, then that's not going to help at all.

                      Also, as far as i was aware, if you upload a file using a post form then the next page isnt loaded until the upload is complete - so the whole uploading process will happen on your form page, meaning that by the time your script is called the uploading will already have happened.

                      I live in hope that there is something that can do it fropm the browser though - they have that upload bar in the status bar at the bottom that shows (more or less) how it's going, so if someone can work out how that works and we can get into it, then that would be fab!

                        2 months later

                        Hi,

                        Actually I have done this by using perl-CGI and PHP. The script I have used to upload is PERL and showing progress bar with PHP. This is working fine.

                        How I have done it..

                        1) In the mail window I have a form from where user selects the file and cliecks on upload button. This fires a CGI-PERL script and file uploading takes place.
                        2) On Click of the above upload button a window will open calling the php with total file size and uploading path. this window gets refresh for every 2 seconds and checks the full size and uploaded size ((uploaded size/fullsize) * 100)) then the percentage will be displayed using normal HTML tables as progress bar. This is working fine for me and works on any browser...

                        with regards
                        venkat.

                          If the browser knows how fast the file is being sent and how large the file is, sure... but if not, no. so on 99.9999% of the browsers, no. It's not a PHP issue at all (PHP won't know the size of the file until it's sent), it's client-size entirely. If you manage to get it working at all, don't expect it to work for anyone else, because it most likely won't.
                          It won't work on IE, Netscape, Mozilla, or any other browser that more than 10 people use, because they have good security in mind.
                          I saw that ActiveX was mentioned.. yeah, it'd be possible with ActiveX, but ActiveX is like a virus programmer's dream. (Don't run it on pages unless they're at least VeriSign registered.)

                            ok obviously there isn't any good way to show the actual timeleft of the upload because there is no way that we can find the filesize of the file. however is there a way to show the transfer rate? ive played with the idea some with using disk_free_space() in a seperate file and refreshing every second or so and using sessions to transfer the data and notice the change. however i dont know how successful its been. anybody else have any ideas?

                              Write a Reply...