<tfoot id='vNHVt'></tfoot>

      <i id='vNHVt'><tr id='vNHVt'><dt id='vNHVt'><q id='vNHVt'><span id='vNHVt'><b id='vNHVt'><form id='vNHVt'><ins id='vNHVt'></ins><ul id='vNHVt'></ul><sub id='vNHVt'></sub></form><legend id='vNHVt'></legend><bdo id='vNHVt'><pre id='vNHVt'><center id='vNHVt'></center></pre></bdo></b><th id='vNHVt'></th></span></q></dt></tr></i><div id='vNHVt'><tfoot id='vNHVt'></tfoot><dl id='vNHVt'><fieldset id='vNHVt'></fieldset></dl></div>
      • <bdo id='vNHVt'></bdo><ul id='vNHVt'></ul>
      <legend id='vNHVt'><style id='vNHVt'><dir id='vNHVt'><q id='vNHVt'></q></dir></style></legend>

      1. <small id='vNHVt'></small><noframes id='vNHVt'>

        PHP 上传、解压和进度条

        时间:2023-12-02

        <tfoot id='dbOk4'></tfoot>

            <bdo id='dbOk4'></bdo><ul id='dbOk4'></ul>

          • <legend id='dbOk4'><style id='dbOk4'><dir id='dbOk4'><q id='dbOk4'></q></dir></style></legend>
            1. <small id='dbOk4'></small><noframes id='dbOk4'>

                • <i id='dbOk4'><tr id='dbOk4'><dt id='dbOk4'><q id='dbOk4'><span id='dbOk4'><b id='dbOk4'><form id='dbOk4'><ins id='dbOk4'></ins><ul id='dbOk4'></ul><sub id='dbOk4'></sub></form><legend id='dbOk4'></legend><bdo id='dbOk4'><pre id='dbOk4'><center id='dbOk4'></center></pre></bdo></b><th id='dbOk4'></th></span></q></dt></tr></i><div id='dbOk4'><tfoot id='dbOk4'></tfoot><dl id='dbOk4'><fieldset id='dbOk4'></fieldset></dl></div>
                    <tbody id='dbOk4'></tbody>
                  本文介绍了PHP 上传、解压和进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我需要帮助来为我的 php 上传网站创建进度条.我已经对上传和提取部分进行了排序,但我需要进度条方面的帮助.我不知道该怎么做.另外,上传文件是否有最大文件大小?

                  I need help with creating a progress bar for my php upload site. I've got the upload and exctract part sorted but i need help with the progress bar. I'm not sure how to do it. Also, is there a maximum file size for the upload?

                  HTML

                  <?php if($message) echo "<p>$message</p>"; ?>
                  <form enctype="multipart/form-data" method="post" action="">
                  <label>Choose file (.zip): <input type="file" name="zip_file" /></label>
                  <br />
                  <input type="submit" value="Upload" name="submit" value="Upload" />
                  </form>
                  

                  PHP

                  <?php
                  if($_FILES["zip_file"]["name"]) {
                    $filename = $_FILES["zip_file"]["name"];
                    $source = $_FILES["zip_file"]["tmp_name"];
                    $type = $_FILES["zip_file"]["type"];
                  
                    $name = explode(".", $filename);
                    $accepted_types = array(
                      'application/zip', 
                      'application/x-zip-compressed', 
                      'multipart/x-zip', 
                      'application/x-compressed');                          
                  
                    foreach($accepted_types as $mime_type) {
                      if($mime_type == $type) {
                        $okay = true;
                        break;
                      } 
                    }
                  
                    $continue = strtolower($name[1]) == 'zip' ? true : false;
                    if(!$continue) {
                      $message = "[...] not a .zip file. Please try again.";
                    }
                    $target_path = "./".$filename;
                    if(move_uploaded_file($source, $target_path)) {
                      $zip = new ZipArchive();
                      $x = $zip->open($target_path);
                      if ($x === true) {
                        $zip->extractTo("./");
                        $zip->close();
                  
                        unlink($target_path);
                      }
                      $message = "Your .zip file was uploaded and unpacked.";
                    } else {  
                      $message = "There was a problem with the upload. Please try again.";
                    }
                  }
                  ?>
                  

                  推荐答案

                  您可以进行一些更改以适应,但如果您想要一个进度条,这会很好.您可以添加更多事件侦听器并按照您的意愿进行操作.我希望这对你来说是一个很好的起点.

                  You can make some changes to fit but this works rather well if you want a progress bar. You can add more eventlisteners and make it how you want. I hope this is a good starting point for you.

                  function uploadFile(){
                      var file = document.getElementById("zip_file").files[0];
                      var formdata = new FormData();
                      formdata.append("zip_file", file);
                      var ajax = new XMLHttpRequest();
                      ajax.upload.addEventListener("progress", function(event) { runprogress(event); } , false);
                      ajax.addEventListener("load", function(event) {uploadcomplete(event); }, false);
                      //Target your php file. 
                      ajax.open("POST", "upload.php");
                      ajax.send(formdata);
                  }
                  function runprogress(event){
                      //The progress %, you might want to Math.round(percent) 
                      var percent = (event.loaded / event.total) * 100;
                  }
                  function uploadcomplete(event){
                      //This will = to your php reply.
                      var AjaxReply=event.target.responseText;
                  }
                  

                  这篇关于PHP 上传、解压和进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 PHP 中使用分块上传 1GB 文件 下一篇:使用 PHP 进行非常大的上传

                  相关文章

                  1. <small id='2oxau'></small><noframes id='2oxau'>

                  2. <tfoot id='2oxau'></tfoot>
                  3. <legend id='2oxau'><style id='2oxau'><dir id='2oxau'><q id='2oxau'></q></dir></style></legend>
                        <bdo id='2oxau'></bdo><ul id='2oxau'></ul>
                    1. <i id='2oxau'><tr id='2oxau'><dt id='2oxau'><q id='2oxau'><span id='2oxau'><b id='2oxau'><form id='2oxau'><ins id='2oxau'></ins><ul id='2oxau'></ul><sub id='2oxau'></sub></form><legend id='2oxau'></legend><bdo id='2oxau'><pre id='2oxau'><center id='2oxau'></center></pre></bdo></b><th id='2oxau'></th></span></q></dt></tr></i><div id='2oxau'><tfoot id='2oxau'></tfoot><dl id='2oxau'><fieldset id='2oxau'></fieldset></dl></div>