php多图像上传进度条

时间:2016-06-17 07:20:51

标签: php html mysql css ajax

我有这个代码将多个图像上传到文件夹,图像的名称和一些其他信息到数据库,他工作得很好

<?php 
include("includes/connect.php");
session_start();
$user=$_SESSION['fl'];
$shopname=$_POST["dep"];
$location=$_POST["cname"];
$status=$_POST["status"];
$notes=mysqli_real_escape_string($conn,$_POST['note']);
$date=date('d-m-Y');

$valid_formats = array("jpg", "png", "gif", "zip", "bmp");
$max_file_size = 1024*100; //100 kb
$path = "uploads_images/"; // Upload directory
$count = 0;

if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST"){
    // Loop $_FILES to exeicute all files
    foreach (preg_replace('/ /','-',($_FILES['myimage']['name'])) as $f => $name) {     
        if ($_FILES['myimage']['error'][$f] == 4) {
            continue; // Skip file if any error found
        }          
        if ($_FILES['myimage']['error'][$f] == 0) {            
           /* if ($_FILES['myimage']['size'][$f] > $max_file_size) {
                $message[] = "$name is too large!.";

                continue; // Skip large files
            }*/
            if( ! in_array(pathinfo($name, PATHINFO_EXTENSION), $valid_formats) ){
                $message[] = "$name is not a valid format";
                continue; // Skip invalid file formats
            }
            else{ // No error found! Move uploaded files 
                if(move_uploaded_file($_FILES["myimage"]["tmp_name"][$f], $path.$name))
                $query=mysqli_query($conn,"INSERT INTO tbl_img(db_imgname,db_shopname,db_location,db_status,db_date,db_notes,db_user)VALUES('$name','$shopname','$location','$status','$date','$notes','$user')") or die(mysqli_error($conn));
        header("location:upload.php?msg=1");
                $count++; // Number of successfully uploaded file
            }
        }
    }
}

?>

如何向此代码添加进度条以向用户显示其上传的进度

0 个答案:

没有答案