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

      <bdo id='087y9'></bdo><ul id='087y9'></ul>

      1. <legend id='087y9'><style id='087y9'><dir id='087y9'><q id='087y9'></q></dir></style></legend>

        <small id='087y9'></small><noframes id='087y9'>

        基于 AJAX/PHP 的大文件上传,带有进度条

        AJAX/PHP based upload with progress bar for large files(基于 AJAX/PHP 的大文件上传,带有进度条)

        <legend id='iOLFm'><style id='iOLFm'><dir id='iOLFm'><q id='iOLFm'></q></dir></style></legend>

          <tfoot id='iOLFm'></tfoot>
            <tbody id='iOLFm'></tbody>
          <i id='iOLFm'><tr id='iOLFm'><dt id='iOLFm'><q id='iOLFm'><span id='iOLFm'><b id='iOLFm'><form id='iOLFm'><ins id='iOLFm'></ins><ul id='iOLFm'></ul><sub id='iOLFm'></sub></form><legend id='iOLFm'></legend><bdo id='iOLFm'><pre id='iOLFm'><center id='iOLFm'></center></pre></bdo></b><th id='iOLFm'></th></span></q></dt></tr></i><div id='iOLFm'><tfoot id='iOLFm'></tfoot><dl id='iOLFm'><fieldset id='iOLFm'></fieldset></dl></div>
            • <small id='iOLFm'></small><noframes id='iOLFm'>

                <bdo id='iOLFm'></bdo><ul id='iOLFm'></ul>
                1. 本文介绍了基于 AJAX/PHP 的大文件上传,带有进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我一直在尝试创建一个非 Flash 上传面板,该面板还显示一个进度条.在我们的服务器上,我们有 PHP 5.3(暂时无法升级到 5.4,因此无法使用新的上传进度功能 => http://php.net/manual/en/session.upload-progress.php).我们不能使用基于闪存的解决方案、扩展或类似的.

                  I've been trying to create a non-flash upload panel which also shows a progress bar. On our server we have PHP 5.3 (cannot upgrade to 5.4 for now, so the new upload progress feature cannot be used => http://php.net/manual/en/session.upload-progress.php). We cannot use flash based solutions, extensions or similar.

                  因此,我尝试将 XMLHttpRequest 与 AJAX 结合使用.这里的问题是我只取得了部分成功.

                  Hence I've tried using an XMLHttpRequest combined with AJAX. The problem here is that I've only achieved partial success.

                  我已经设法在服务器上上传并保存了一个大约 380 MB 的文件,但是,当尝试使用 4 GB 等更大的文件时,它不会保存在服务器上(如果我与 Firebug 核对一下点它会说POST aborted").

                  I've managed to upload and save on the server a file of about 380 MB, however, when trying with a larger file like 4 GB, it won't be saved on the server (if I check with Firebug at one point it would say "POST aborted").

                  另一个奇怪的是,对于同一个文件,xhr.upload.loaded 以 xhr.upload.total 的相同维度开始,并从那里开始计数.

                  Another strange thing is that with the same file the xhr.upload.loaded starts with the same dimension of xhr.upload.total and starts counting from there.

                  有谁知道如何解决这个问题或有替代解决方案?

                  Does anyone know how to solve this problem or has an alternative solution?

                  客户端代码是:

                  <script type="application/javascript" src="jquery.js"></script>
                  
                  <script type="application/javascript">
                  
                  function uploadToServer()
                  {
                      fileField = document.getElementById("uploadedFile");
                      var fileToUpload = fileField.files[0]; 
                  
                      var xhr = new XMLHttpRequest();
                      var uploadStatus = xhr.upload;
                  
                      uploadStatus.addEventListener("progress", function (ev) {
                              if (ev.lengthComputable) {
                                  $("#uploadPercentage").html((ev.loaded / ev.total) * 100 + "%");
                              }
                          }, false);
                  
                      uploadStatus.addEventListener("error", function (ev) {$("#error").html(ev)}, false);
                      uploadStatus.addEventListener("load", function (ev) {$("#error").html("APPOSTO!")}, false);
                  
                      xhr.open(
                              "POST",
                              "serverUpload.php",
                              true
                              );
                          xhr.setRequestHeader("Cache-Control", "no-cache");
                          xhr.setRequestHeader("Content-Type", "multipart/form-data");
                          xhr.setRequestHeader("X-File-Name", fileToUpload.fileName);
                          xhr.setRequestHeader("X-File-Size", fileToUpload.fileSize);
                          xhr.setRequestHeader("X-File-Type", fileToUpload.type);
                          //xhr.setRequestHeader("Content-Type", "application/octet-stream");
                          xhr.send(fileToUpload);
                  }
                  
                  
                  
                  $(function(){
                  
                      $("#uploadButton").click(uploadToServer);
                  
                  });
                  
                  
                  </script>
                  

                  HTML 部分:

                  <form action="" name="uploadForm" method="post" enctype="multipart/form-data">
                  
                    <input id="uploadedFile" name="fileField" type="file" multiple />
                  
                  <input id="uploadButton" type="button" value="Upload!">
                  
                  </form>
                  
                  <div id="uploadPercentage"></div>
                  <div id="error"></div>
                  

                  服务器端代码:

                  <?php
                  
                  $path = "./";
                  $filename = $_SERVER['HTTP_X_FILE_NAME'];
                  $filesize = $_SERVER['CONTENT_LENGTH'];
                  
                  
                  $file = "log.txt";
                  $fo= fopen($file, "w");
                  fwrite($fo, $path . PHP_EOL);
                  fwrite($fo, $filename . PHP_EOL);
                  fwrite($fo, $filesize . PHP_EOL);
                  fwrite($fo, $path . $filename . PHP_EOL);
                  
                  file_put_contents($path . $filename, 
                  file_get_contents('php://input')
                  );
                  
                  ?>
                  

                  推荐答案

                  PHP 无法更改与 Web 服务器相关的限制.例如,它们是 IIS 中 30MB 的默认最大发布请求大小......还有一个您可能会遇到的最大超时.与大小无关,但您的发布请求需要多长时间......即文件提交需要多长时间.这两种设置都可以受 IIS 或 Apache 的约束.

                  There are limits associated with the web server that can't be changed by PHP. Example, their is a default max post request size of 30MB in IIS...there is also a max timeout which you may be hitting. Has nothing to do with size, but how long your post request is taking...ie, how long its taking for the file submit. Both settings can be constrained by IIS or Apache.

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

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                  • <legend id='TkDXM'><style id='TkDXM'><dir id='TkDXM'><q id='TkDXM'></q></dir></style></legend>

                      <bdo id='TkDXM'></bdo><ul id='TkDXM'></ul>
                      <tfoot id='TkDXM'></tfoot>

                      1. <i id='TkDXM'><tr id='TkDXM'><dt id='TkDXM'><q id='TkDXM'><span id='TkDXM'><b id='TkDXM'><form id='TkDXM'><ins id='TkDXM'></ins><ul id='TkDXM'></ul><sub id='TkDXM'></sub></form><legend id='TkDXM'></legend><bdo id='TkDXM'><pre id='TkDXM'><center id='TkDXM'></center></pre></bdo></b><th id='TkDXM'></th></span></q></dt></tr></i><div id='TkDXM'><tfoot id='TkDXM'></tfoot><dl id='TkDXM'><fieldset id='TkDXM'></fieldset></dl></div>
                          <tbody id='TkDXM'></tbody>

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