Php: how to upload a file and display the upload progress,
This example describes how to upload a file and display the upload progress in php. Share it with you for your reference. The details are as follows:
Remember to make the file bigger when you upload it. Otherwise, the file will be uploaded even if you haven't seen it yet, and the file to be uploaded should not be too large. If you want to upload the file to G, I tried it for 2 GB, and PHP couldn't stand it, I tested more than 300 M. Remember to adjust the small php. ini parameter ah "select file =" Submit = "get information" needs to be done in one breath ^
<? Php $ prefix = ini_get ('session. upload_progress.prefix'); $ name = ini_get ('session. upload_progress.name '); $ key = $ prefix. $ name; session_start (); if (isset ($ _ POST ['get _ info']) {$ logo = $ prefix. $ _ POST ['logo ']; exit (json_encode ($ _ SESSION [$ logo]);} elseif ($ _ POST) {echo '<script> var finashed = true; </script>' ;}?> <Div id = "show_info_div"> </div> <form action = "index. php "method =" POST "enctype =" multipart/form-data "> <input type =" hidden "name =" <? Php echo $ name;?> "Value =" test "> <input type =" file "name =" file "> <br> <input type =" submit "value =" submit "> <input type = ""button" value = "get information" onclick = "getUploadInfo () "> </form> <script src =" jquery. js "> </script> <script> var sto = null; var progress = null; function getUploadInfo () {$. post ("index. php ", {" get_info ": 1," logo ":" test "}, function (data) {data = eval (" ("+ data + ")"); progress = parseInt (data. bytes_proces Sed) * 10000/parseInt (data. content_length)/100 + "%"; document. getElementById ("show_info_div "). innerHTML = progress; sto = setTimeout ("getUploadInfo ()", 1000) ;};} if (typeof (finashed )! = "Undefined") {document. getElementById ("show_info_div"). innerHTML = "100.00% (uploaded successfully !) ";}</Script>
I hope this article will help you with php programming.