<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="refresh" content="5; url=upload.php">
<style>
body{
font-size:18px; 
font-family:arial; 
background:white; 
padding:2px;
max-width:350px; 
margin:5px auto;
}

a, a:active, a:visited {color:#000066;}
a:hover {color:#00ff00;}

.clgr {color:red;}
.clgr2 {color:blue;}
.clgr3 {color:limegreen;}
.clgr4 {color:#000099;}
.clgr5 {color:#ff6600;}
.clgr6 {color:#cc0099;}
.clgr7 {color:#00cc00;}

</style>


<?php
$target_dir = "images/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));

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

// Check if file already exists
if (file_exists($target_file)) {
  echo "<br> <span class='clgr2'> Sorry, file already exists.</span>";
  $uploadOk = 0;
}

// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
  echo "<br> <span class='clgr3'> Sorry, your file is too large.</span>";
  $uploadOk = 0;
}

// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
  echo "<br> <span class='clgr4'> Sorry, only JPG, JPEG, PNG & GIF files are allowed.</span>";
  $uploadOk = 0;
}

// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
  echo "<br> <span class='clgr5'> Sorry, your file was not uploaded.</span>";
// if everything is ok, try to upload file
} else {
  if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
    echo "<br> <h3> <span class='clgr7'> The file <span class='clgr6'>".htmlspecialchars( basename( $_FILES["fileToUpload"]["name"]))." </span> has been uploaded.</span></h3>";
  } else {
    echo "<br> <span class='clgr6'> Sorry, there was an error uploading your file.</span>";
  }
}
?>
<h3><b>&nbsp; &nbsp;<a href="upload.php"> BACK TO HOME PAGE</a></b></h3>