如何在使用php上传表单时附加进度条


how to attach progressbar while uploading form using php

我有一个表单上传图像与标题到服务器,成功上传后,它会重定向到另一个页面。在上传图像时,我想在那里显示进度条,并在成功上传后重定向到另一个页面。
我知道PHP,也在谷歌上搜索了一下progressbar。所有的链接都只与javascript有关,我是新的javascript。有人能帮我一下吗?这里是upload。php包含表单

<form action="newupload.php" enctype="multipart/form-data" method="post">
    <div class="form-group">
        <div id="image-cropper">
            <div class="cropit-preview"></div>
            <input type="file" name="user_image" class="cropit-image-input" style="font-weight: bold;" />
        </div>
    </div>
    <div class="form-group">
        <input type="text" name="title" class="input-round big-input" id="title-modal" placeholder="Enter your Image Title" required/>
        <input type="hidden" name="category" value="<?php echo $category; ?>" />
        <input type="hidden" name="hashtag" value="<?php echo $hashtag; ?>" />
    </div>
    <div class="form-group">
        <!-- required  -->
        <span class="required margin-three">*Please complete all fields correctly</span>
        <!-- end required  -->
        <p class="text-center">
            <!-- button  -->
            <button class="btn btn-black no-margin-bottom btn-medium btn-round no-margin-top" type="submit">Submit</button>
            <!-- end button  -->
        </p>
    </div>
</form>

这是用于移动和更新数据库的newupload.php文件

<?php
define("MAX_SIZE", "400");
include ('mysqli_connect.php');
session_start();
$email = $_SESSION['user_email'];
$q = "select * from user where u_email='$email'";
$qres = mysqli_query($dbc, $q);
$qrow = mysqli_fetch_array($qres, MYSQLI_ASSOC);
$u_id = $qrow['u_id'];
function getExtension($str)
  {
  $i = strrpos($str, ".");
  if (!$i)
    {
    return "";
    }
  $l = strlen($str) - $i;
  $ext = substr($str, $i + 1, $l);
  return $ext;
  }
if ($_SERVER["REQUEST_METHOD"] == "POST")
  {
  $image = $_FILES['user_image']['name'];
  $uploadedfile = $_FILES['user_image']['tmp_name'];
  $image_title = $_POST['title'];
  $category = $_POST['category'];
  $hashtag = $_POST['hashtag'];
  if ($image)
    {
    $filename = stripslashes($_FILES['user_image']['name']);
    $extension = getExtension($filename);
    $extension = strtolower($extension);
    if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))
      {
      echo ' Unknown Image extension ';
      $errors = 1;
      }
      else
      {
      $size = filesize($_FILES['user_image']['tmp_name']);
      if ($extension == "jpg" || $extension == "jpeg")
        {
        $uploadedfile = $_FILES['user_image']['tmp_name'];
        $src = imagecreatefromjpeg($uploadedfile);
        }
        else
      if ($extension == "png")
        {
        $uploadedfile = $_FILES['user_image']['tmp_name'];
        $src = imagecreatefrompng($uploadedfile);
        }
        else
        {
        $src = imagecreatefromgif($uploadedfile);
        }
      $maxwidth = 800;
      list($width, $height) = getimagesize($uploadedfile);
      if ($width >= $maxwidth)
        {
        $newwidth = 800;
        $newheight = ($maxwidth / $width) * $height;
        }
        else
        {
        $newwidth = $width;
        $newheight = $height;
        }
      $tmp = imagecreatetruecolor($newwidth, $newheight);
      imagecopyresampled($tmp, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
      $t = uniqid();
      $filenamee = 'user-' . $t;
      $path = 'uploaded/';
      $filename = $path . $filenamee . ".jpg";
      move_uploaded_file($_FILES['user_image']['tmp_name'], $filename);
      (u_id, s_category, s_title, s_upload, s_maxupload) values('$u_id', '$category', '$image_title', '$filename', '$mfilename') ";
 $query="insertintoselfiepost(u_id, s_category, s_title, s_upload, s_hashtag, upload_time) values('$u_id', '$category', '$image_title', '$filename', '$hashtag', now()) ";
    $res=mysqli_query($dbc,$query);
    if($res){
        header('Location:home.php?insert=1');
   } else{
            header('Location:home.php?insert=0');
        }
    }}
    }
    ?>

在PHP中不可能为上传制作进度条,因为它是服务器端,当你上传一些东西时,它从你的计算机到服务器(或称为下载)。

有效的方法是在javascript和PHP中完成。

也许你可以看看这里:https://www.sitepoint.com/tracking-upload-progress-with-php-and-javascript/