<?php
    $img = $_POST['image'];
    $folderPath = "../uploads/gatepass/";
  
    $image_parts = explode(";base64,", $img);
    $image_type_aux = explode("image/", $image_parts[0]);
    $image_type = $image_type_aux[1];
  
    $image_base64 = base64_decode($image_parts[1]);
    $fileName = uniqid() . '.png';
  
    $file = $folderPath . $fileName;
    $a = file_put_contents($file, $image_base64);
  
    echo $fileName;
    
// if(isset($_FILES['file']['name'])){

//   /* Getting file name */
//   $filename = $_FILES['file']['name'];

//   /* Location */
//   $location = "../uploads/gatepass/".$filename;
//   $imageFileType = pathinfo($location,PATHINFO_EXTENSION);
//   $imageFileType = strtolower($imageFileType);

//   /* Valid extensions */
//   $valid_extensions = array("jpg","jpeg","png");

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

//   echo $filename;
//   exit;
// }

// echo 0;