<?php

$folder_name = "api/img/";
$bg_img = $folder_name . "gifbg.gif";
if (isset($_POST["images"])) {
    $errors = [];
    $file_name = $_FILES["image"]["name"];
    $file_size = $_FILES["image"]["size"];
    $file_tmp = $_FILES["image"]["tmp_name"];
    $file_type = $_FILES["image"]["type"];
    $file_ext = strtolower(end(explode(".", $_FILES["image"]["name"])));
    $extensions = ["jpeg", "jpg", "png", "gif", "JPEG", "JPG", "PNG", "GIF", "mp4", "MP4"];
    if (in_array($file_ext, $extensions) === false) {
        $errors[] = "extension not allowed, please choose a JPEG or PNG or GIF or MP4 file.";
    }
    if (11242880 < $file_size) {
        $errors[] = "File size must not exceed 5 MB";
    }
    if (empty($errors)) {
        if ($_POST["image"] == "gif") {
            $file_name1 = "gifbg.gif";
        }
        move_uploaded_file($file_tmp, $folder_name . $file_name1);
        header("Location: " . $_SERVER["PHP_SELF"]);
    } else {
        print_r($errors);
    }
}
include "includes/header.php";
echo " <!-- Begin Page Content -->\n        <div class=\"container-fluid\">\n\n";
if (isset($_GET["message"])) {
    echo $_GET["message"];
}
echo "          <!-- Content Row -->\n          <div class=\"row\">\n\n            <!-- First Column -->\n            <div class=\"col-lg-12\">\n\n              <!-- Custom codes -->\n                <div class=\"card text-text-primary\">\n                <div class=\"card-header bg-primary py-3\">\n                <center><h4 align=\"center\" class=\"m-0 text-white\"><i class=\"fa fa-image\"\n                                    style=\"font-size:20px\">&nbsp;&nbsp;</i>Background Changes</h4>\n                        \n\t\t\t\t\t\t</center>\n\n            </div>\n                <div class=\"card-body\">\n\t\t\t\t\t\t<form method=\"post\" enctype=\"multipart/form-data\">\t\t\t\t\t\t\t<div class=\"form-group \">\n                            <label class=\" text-primary control-label requiredField\" for=\"aa\" >\n                                <strong> Upload Background File</strong>\n                            </label>\n<div class=\"input-group\">\n\t\t\t\t\t\t\t\t<div class=\"custom-file\">\n\t\t\t\t\t\t\t\t\t<input type=\"file\" class=\"custom-file-input\" name=\"image\" id=\"intro\" placeholder=\"Choose Background\" onchange=\"uploadintro(this)\" aria-describedby=\"intro\">\n\t\t\t\t\t\t\t\t\t<label class=\"custom-file-label\" for=\"intro\" placeholder=\"Choose Background\"><span id=\"image-intro\"></span></label>\n\t\t\t\t\t\t\t\t\t<input type=\"hidden\" name=\"image\" value=\"gif\">\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t<button type=\"submit\" name=\"images\" class=\"btn btn-primary\">Upload</button>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</form>\n\t\t\t\t\t\t<br>\n\t\t\t\t\t\t\n\t\t\t\t\t</div>\n            <!-- Theme -->\n              <div class=\"card border-left-primary shadow py-2  align-items-center\">\n <center>     <h6 class=\"m-0 font-weight-bold text-primary align-center\"><i class=\"fa fa-image\"></i> Current Background <br><center></h6>\n              </div>\n              <div class=\"card border-left-primary shadow py-2  align-items-center\">\n <center>\n";
echo "                     <img class=\"card-img-bottom\" src=\"" . $bg_img . "\" alt=\"Card image\" style=\"width:100%; height:100%\"></div>" . "\n";
echo "                    \n            </div>\n            </div>\n          </div>\n</center>      \n<br><br>\n    </body>\n</html><script src=\"https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js\"></script>\n<script src=\"https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js\"></script>\n<script>\nfunction uploadintro(target) {\n\tdocument.getElementById(\"image-intro\").innerHTML = target.files[0].name;\n}\n\n\$(document).ready(function() {\n    if (location.hash) {\n        \$(\"a[href='\" + location.hash + \"']\").tab(\"show\");\n    }\n    \$(document.body).on(\"click\", \"a[data-toggle='tab']\", function(event) {\n        location.hash = this.getAttribute(\"href\");\n    });\n});\n\$(window).on(\"popstate\", function() {\n    var anchor = location.hash || \$(\"a[data-toggle='tab']\").first().attr(\"href\");\n    \$(\"a[href='\" + anchor + \"']\").tab(\"show\");\n});\n\n</script>    <br><br><br>";
include "includes/footer.php";
echo "</body>\n";

?>