douyin2883 2016-08-11 08:18 采纳率: 0%
浏览 32

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

I have a form to upload image with title to server and after successfully upload, it will redirect you to another page. While uploading of image I want to show progressbar there and also redirect to another page after successfully uploading.
I know about PHP and also did googling about progressbar. All link is related to javascript only and I am new to javascript. Can someone please help me with this. Here is upload.php contains form

<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>

Here is newupload.php file for move and update database

<?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');
        }
    }}
    }
    ?>
  • 写回答

1条回答 默认 最新

  • dqoeghe9452 2016-08-11 08:24
    关注

    it's not possible to make a progressbar for the upload in PHP, because its server-side, when you upload something its from your computer to the server (or its called download).

    The efficient way is to do it in javascript and PHP.

    Maybe you can take a look here : https://www.sitepoint.com/tracking-upload-progress-with-php-and-javascript/

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。