【问题标题】:php file upload with a progressbar or number of percent带有进度条或百分比数的 php 文件上传
【发布时间】:2013-05-14 08:35:44
【问题描述】:

我想使用文件上传进度。任何人都可以给出可能的简单代码 用于显示上传进度条。在下一个代码上。 有文件接收文件upload.php

<?php
if ($_FILES) {
    foreach ($_FILES as $k => $v) {
        if ($v["error"] > 0) {
            echo "Error: " . $_FILES["file"]["error"] . "<br>";
        } else {
            echo "Upload: " . $v["name"] . "<br>";
            echo "Type: " . $v["type"] . "<br>";
            echo "Size: " . ($v["size"] / 1024) . " kB<br>";
            echo "Stored in: " . $v["tmp_name"]. "<br><br>";
        }
    }
    return;
}
?>

还有一个带有文件上传表单的html。

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Upload</title>
    </head>
    <body>
        <form action="upload.php" method="post" enctype="multipart/form-data">
            <label for="f1">Filename:</label>
            <input type="file" name="f1" id="f1"><br>
            <label for="f2">Filename:</label>
            <input type="file" name="f2" id="f2"><br>
            <input type="submit" name="submit" value="Submit">
        </form>
    </body>
</html>

谢谢

【问题讨论】:

标签: php html


【解决方案1】:

最简单的方法是使用 jQuery uploadify 插件,它包含 swfobject 并显示文件上传进度条。这是上传多个文件的好方法。

jQuery 上传插件:

http://www.uploadify.com/

如果您想按照自己的方式进行操作,则需要服务器端兼容性,一些可以处理上传进度的 nginx 或 apache2 模块。并且您的客户端应该在所有上传过程中向服务器发出请求以获取有关它的所有信息。

【讨论】:

    【解决方案2】:

    您可以使用 jQuery 表单插件来实现这一点。 只需将 jQuery Form 插件添加到您的页面头部部分。您可以使用以下代码。

    $(function() {
     $(document).ready(function(){
     var percent = $('#percent');
     var status = $('#status');
     $('form').ajaxForm({
     beforeSend: function() {
     status.empty();
     var percentVal = '0%';
     percent.html(percentVal);
     },
     uploadProgress: function(event, position, total, percentComplete) {
     var percentVal = percentComplete + '%';
     percent.html(percentVal);
     },
     complete: function(xhr) {
     status.html(xhr.responseText);
    }
     });
    });
    });
    

    我从这个File Upload Progress Bar 教程中得到它。它工作得非常好。

    【讨论】:

      猜你喜欢
      • 2016-05-04
      • 2014-03-05
      • 2011-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-04
      • 2017-08-03
      • 1970-01-01
      相关资源
      最近更新 更多