<?PHP 
require_once ("../var/res.php");
// $quee = $db->prepare('SELECT * FROM tbl_user_accounts u
// INNER JOIN tbl_role r ON r.role_id=u.user_role 
// INNER JOIN tbl_user_access a ON a.last_acc = u.user_id
// INNER JOIN tbl_info_register i ON i.acc_sder = u.user_id 
// ');
// $quee->execute();
// while($ff = $quee->fetch()){
//     $userid = $ff['user_id'];
//     $tle_id = $ff['title_id'];

// // $sql = $db->query("UPDATE `tbl_con_infos` SET `recvappnt` = '$tle_id' WHERE iRcv = '$userid' ");  
// $sql = $db->query("UPDATE `tbl_docs` SET `docAppoint` = '$tle_id' WHERE usID = '$userid' ");  

// echo 2;
// }
?>

<!doctype html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Multiple files upload at once with php</title>
</head>
<body >
    
    <span style='color: red;margin-bottom:8px; margin-top:10px;'>NOTE - Files not upload to the server only displaying names of file. </span><br/>
    <form method='post' action='' enctype='multipart/form-data'>
         <input type="file" name="file[]" id="file" multiple><br/><br/>

         <input type='submit' name='submit' value='Upload'>
    </form>
    <?php
    if(isset($_POST['submit'])){

         ######## FILES UPLOAD #############
   $countfiles = count($_FILES['file']['name']);

   $totalFileUploaded = 0;
   for($i=0;$i<$countfiles;$i++){
    $stms_last = $db->prepare("SELECT doc_id FROM tbl_docs  ORDER BY doc_id DESC LIMIT 1");
       try {
           $stms_last->execute(array());
           $row_count_last = $stms_last->rowCount();
           if ($row_count_last > 0) {
               $rows = $stms_last->fetch(PDO::FETCH_ASSOC);
                   $doc_id = $rows['doc_id']+1;
            }else{
               $doc_id = 1;
            }
       }
       catch (PDOException $ex) {
        echo $ex->getMessage();
       } 

         
        $filename = $doc_id."_".$_FILES['file']['name'][$i];

        ## Location
        $location = $path_upload.$filename;
        $extension = pathinfo($location,PATHINFO_EXTENSION);
        $extension = strtolower($extension);

        ## File upload allowed extensions
        $valid_extensions = array("jpg","jpeg","png","pdf","doc","docx","xls","xlsx","ppt","pptx","zip","tar"."gz");

        $response = 0;
        ## Check file extension
        if(in_array(strtolower($extension), $valid_extensions)) {
             ## Upload file
             if(move_uploaded_file($_FILES['file']['tmp_name'][$i],$location)){

                   echo "file name : ".$filename."<br/>";

                   $totalFileUploaded++;
             }
        }

   }
         echo "Total File uploaded : ".$totalFileUploaded;
    }
    ?>
</body>
</html>