1

I have this code to upload multi images to the folder and the name of images and some other information to the database and he work good

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

?>

how can i add a progress bar to this code to show for user the progress of his upload

jad
  • 37
  • 5
  • Possible duplicate of [Simple cross-browser, jQuery/PHP file upload with progress bar](http://stackoverflow.com/questions/10477135/simple-cross-browser-jquery-php-file-upload-with-progress-bar) –  Jun 17 '16 at 07:29
  • 1
    A PHP file returns an output upon parsing, and only one output. You can't see the progress of the parsing. However, you can use JavaScript with Ajax in combination with PHP to achieve this progress of the upload, see @theinarasu 's link. – andreini Jun 17 '16 at 07:43
  • i try this code http://www.w3bees.com/2013/12/multiple-file-upload-with-progress-bar.html but he print {"count":2} only not a progress bar any idea to correct upload to folder work correct and insert to database work correct – jad Jun 17 '16 at 09:14

0 Answers0