• <small id='IIisU'></small><noframes id='IIisU'>

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

      <tfoot id='IIisU'></tfoot>
      • <bdo id='IIisU'></bdo><ul id='IIisU'></ul>

        PHP Ajax 上传进度条

        PHP Ajax Upload Progress Bar(PHP Ajax 上传进度条)

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

        <small id='auWLO'></small><noframes id='auWLO'>

            <tbody id='auWLO'></tbody>
            <bdo id='auWLO'></bdo><ul id='auWLO'></ul>

                • 本文介绍了PHP Ajax 上传进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  <form enctype="multipart/form-data" action="upload.php" method="POST">
                  <input name="uploaded" type="file" />
                  <input type="submit" value="Upload" />
                  </form>
                  
                  <?php
                  if(isset($_REQUEST['submit'])){
                     $target = "data/".basename( $_FILES['uploaded']['name']) ;
                     move_uploaded_file($_FILES['uploaded']['tmp_name'], $target);
                  }
                  ?>
                  

                  我非常了解 Javascript、AJAX 和 JQuery 等,我相信可以使用 PHP、AJAX 和 Javascript 等创建上传进度条.

                  I know Javascript, AJAX and JQuery etc very well and I believe an upload progress bar can be created using PHP, AJAX and Javascript etc.

                  我很惊讶如何在正在上传.

                  这是 PHP 手册的链接,但我不明白:http://php.net/manual/en/session.upload-progress.php

                  Here is link to the PHP manual but I didn't understand that: http://php.net/manual/en/session.upload-progress.php

                  有没有其他方法可以使用 PHP 和 AJAX 显示上传进度条,但不使用 PHP 的任何外部扩展?我无权访问 php.ini

                  Is there any other method to show the upload progress bar using PHP and AJAX but without use of any external extension of PHP? I don't have access to php.ini

                  推荐答案

                  简介

                  PHP Doc 说得很详细

                  Introduction

                  The PHP Doc is very detailed it says

                  当上传正在进行时,上传进度将在 $_SESSION 超全局中可用,并且当 POST 与 session.upload_progress.name INI 设置设置为同名的变量时.当 PHP 检测到此类 POST 请求时,它将在 $_SESSION 中填充一个数组,其中索引是 session.upload_progress.prefix 和 session.upload_progress.name INI 选项的连接值.通常通过读取这些 INI 设置来检索密钥,即

                  The upload progress will be available in the $_SESSION superglobal when an upload is in progress, and when POSTing a variable of the same name as the session.upload_progress.name INI setting is set to. When PHP detects such POST requests, it will populate an array in the $_SESSION, where the index is a concatenated value of the session.upload_progress.prefix and session.upload_progress.name INI options. The key is typically retrieved by reading these INI settings, i.e.

                  您需要的所有信息都已在 PHP 会话命名中准备就绪

                  All the information you require is all ready in the PHP session naming

                  • 开始时间
                  • 内容长度
                  • bytes_processed
                  • 文件信息(支持多个)

                  您只需提取此信息并将其显示在您的 HTML 表单中.

                  All you need is to extract this information and display it in your HTML form.

                  <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css"
                  rel="stylesheet" type="text/css" />
                  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
                  <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
                  <script type="text/javascript">
                      var intval = null;
                      var percentage = 0 ;
                      function startMonitor() {
                          $.getJSON('b.php',
                          function (data) {
                              if (data) {
                                  percentage = Math.round((data.bytes_processed / data.content_length) * 100);
                                  $("#progressbar").progressbar({value: percentage});
                                  $('#progress-txt').html('Uploading ' + percentage + '%');
                  
                              }
                              if(!data || percentage == 100){
                                  $('#progress-txt').html('Complete');
                                  stopInterval();
                              }
                          });
                      }
                  
                      function startInterval() {
                          if (intval == null) {
                              intval = window.setInterval(function () {startMonitor()}, 200)
                          } else {
                              stopInterval()
                          }
                      }
                  
                      function stopInterval() {
                          if (intval != null) {
                              window.clearInterval(intval)
                              intval = null;
                              $("#progressbar").hide();
                              $('#progress-txt').html('Complete');
                          }
                      }
                  
                      startInterval();
                  </script>
                  

                  b.php

                  session_start();
                  header('Content-type: application/json');
                  echo json_encode($_SESSION["upload_progress_upload"]);
                  

                  PHP 会话上传进度示例

                  这里是 PHP 会话上传的一个更好的优化版本进展

                  $('#fileupload').bind('fileuploadsend', function (e, data) {
                      // This feature is only useful for browsers which rely on the iframe transport:
                      if (data.dataType.substr(0, 6) === 'iframe') {
                          // Set PHP's session.upload_progress.name value:
                          var progressObj = {
                              name: 'PHP_SESSION_UPLOAD_PROGRESS',
                              value: (new Date()).getTime()  // pseudo unique ID
                          };
                          data.formData.push(progressObj);
                          // Start the progress polling:
                          data.context.data('interval', setInterval(function () {
                              $.get('progress.php', $.param([progressObj]), function (result) {
                                  // Trigger a fileupload progress event,
                                  // using the result as progress data:
                                  e = document.createEvent('Event');
                                  e.initEvent('progress', false, true);
                                  $.extend(e, result);
                                  $('#fileupload').data('fileupload')._onProgress(e, data);
                              }, 'json');
                          }, 1000)); // poll every second
                      }
                  }).bind('fileuploadalways', function (e, data) {
                      clearInterval(data.context.data('interval'));
                  });
                  

                  progress.php

                  $s = $_SESSION['upload_progress_'.intval($_GET['PHP_SESSION_UPLOAD_PROGRESS'])];
                  $progress = array(
                          'lengthComputable' => true,
                          'loaded' => $s['bytes_processed'],
                          'total' => $s['content_length']
                  );
                  echo json_encode($progress);
                  

                  其他例子

                  • 使用 PHP 和 JavaScript 跟踪上传进度
                  • PHP-5.4-Upload-Progress-Example
                  • 这篇关于PHP Ajax 上传进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  PHP Upload File Validation(PHP 上传文件验证)
                  PHP Error - Uploading a file(PHP 错误 - 上传文件)
                  How can I write tests for file upload in PHP?(如何在 PHP 中编写文件上传测试?)
                  php resizing image on upload rotates the image when i don#39;t want it to(php在上传时调整图像大小会在我不想要它时旋转图像)
                  How to send additional data using PLupload?(如何使用 PLupload 发送附加数据?)
                  change button text in js/ajax after mp4 =gt;mp3 conversion in php(在 php 中的 mp4 =gt;mp3 转换后更改 js/ajax 中的按钮文本)

                  <small id='NYRFI'></small><noframes id='NYRFI'>

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

                          <tbody id='NYRFI'></tbody>

                            <legend id='NYRFI'><style id='NYRFI'><dir id='NYRFI'><q id='NYRFI'></q></dir></style></legend>
                            <tfoot id='NYRFI'></tfoot>