<?php

$target_dir = "uploads/";
$target_dir2 = "ocr/";
$datum = mktime(date('H')+0, date('i'), date('s'), date('m'), date('d'), date('y'));
$target_file = $target_dir . trim(basename($_FILES["imageFile"]["name"]));
$target_file2 = $target_dir2 . trim(basename($_FILES["imageFile"]["name"]));
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);

// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
  $check = getimagesize($_FILES["imageFile"]["tmp_name"]);
  if($check !== false) {
    echo "File is an image - " . $check["mime"] . ".";
    $uploadOk = 1;
  }
  else {
    echo "File is not an image.";
    $uploadOk = 0;
  }
}

// Check file size
if ($_FILES["imageFile"]["size"] > 500000) {
  echo "File is too large.";
  $uploadOk = 0;
}

// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "jpeg") {
 echo "Only only JPG files are allowed.";
 echo $imageFileType, "\n";
 $uploadOk = 0;
}

// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
  echo "File not uploaded.";
// if everything is ok, try to upload file
}
else {
  if (move_uploaded_file($_FILES["imageFile"]["tmp_name"], $target_file)
      && copy($target_file, $target_file2)) 
  {
    echo "The file ". trim(basename( $_FILES["imageFile"]["name"])). " has been uploaded.";
    copy($target_file, $target_dir2 . basename($_FILES["imageFile"]["name"]));
  }
  else {
    echo "Error when uploading file.";
  }
}
?>
