This article describes how to upload files and display the upload progress of php. Share it for your reference. The details are as follows:
Remember to upload files larger, otherwise you will be uploaded before you can see them, and the uploaded files should not be too large. Just forget about the ones that are on G. I tried 2G. PHP can't stand it. I tested more than 300M. Remember to adjust the small parameters. "Select file = 》 Submit = 》 to obtain information" and you have to complete it in one go^ ^
<?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 ></div> <form action="" 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=""></script> <script> var sto = null; var progress = null; function getUploadInfo() { $.post("", {"get_info": 1, "logo": "test"}, function(data) { data = eval("(" + data + ")"); progress = parseInt(parseInt(data.bytes_processed) * 10000 / parseInt(data.content_length)) / 100 + "%"; ("show_info_div").innerHTML = progress; sto = setTimeout("getUploadInfo()", 1000); }); } if (typeof(finashed) !== "undefined") { ("show_info_div").innerHTML = "100.00% (Upload successfully!)"; } </script>
I hope this article will be helpful to everyone's PHP programming.