<?php
include $_SERVER['DOCUMENT_ROOT'] . "/WebBuilder/WebApp.class.php";
$db = new DBMain();

$column_name = key($_FILES);

$target_dir = "uploads/";
$target_file = $target_dir . "client_logo_" . basename($_FILES["$column_name"]["name"]);

// check if the file already exists
if (file_exists($target_file)) {
  echo "Sorry, file already exists.";
  $uploadOk = 0;
} else {
  echo $target_file;
}

$uploadOk = 1;

$imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION));

// Allow certain file formats
if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg") {
  echo "imageFileType : " . $imageFileType;
  echo "Sorry, only JPG, JPEG, PNG files are allowed";
  $uploadOk = 0;
}

// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
  echo "Sorry, your file was not uploaded.";
  // if everything is ok, try to upload file
} else {
  if (move_uploaded_file($_FILES["$column_name"]["tmp_name"], $target_file)) {
    // echo 1;
    echo basename($_FILES["$column_name"]);
  } else {
    echo $_FILES["$column_name"]["tmp_name"]; 
    echo "  Sorry, there was an error uploading your file.  ";
    echo $target_file;
  }
}
?>