include './includes/fonctions.php';
    if (isset($_FILES['affiche']) && $_FILES['affiche']['size'] != 0) {
        $img = './images/' . basename($_FILES['affiche']['name']);
        if (move_uploaded_file($_FILES['affiche']['tmp_name'], utf8_decode($img))) {
        } else {
            echo "Erreur 404 img not found";
        }
    } else {
        $img = escape('');
    }
    $titre = escape($_POST['titre']);
    $desc_short = escape($_POST['descc']);
    $desc_long = escape($_POST['descl']);
    $real = escape($_POST['real']);
    $annee = escape($_POST['annee']);
    ajouterFilm($titre, $desc_short, $desc_long, $real, $annee, $img);
    ?>
                <script language='javascript'>
                    alert('Ajout avec Succès');
                    window.location.replace('./index.php');
                </script>
                <?php 
}
?>
        
        <div class="container">
            <div class="jumbotron">
                <h2 class="text-center">Ajouter un film</h2>
                </br>
            
                <form method="post" action="./ajout.php" enctype="multipart/form-data"  class="form-horizontal">
        echo '
            <div class="alert alert-danger">
              <strong>Fail!</strong> Sorry, your file was not uploaded.
            </div>';
        // if everything is ok, try to upload file
    } else {
        if (move_uploaded_file($_FILES["image"]["tmp_name"], $target_file)) {
            // Ajout du film à la bd
            $mov_title = $_POST["title"];
            $mov_desc_c = $_POST["short_description"];
            $mov_desc_l = $_POST["long_description"];
            $mov_director = $_POST["director"];
            $mov_year = $_POST["year"];
            $cat_id = $_POST["cat_id"];
            $mov_image = $_FILES["image"]["name"];
            ajouterFilm($idConnexion, $mov_title, $mov_desc_c, $mov_desc_l, $mov_director, $mov_year, $mov_image, $cat_id);
            echo ' 
            <div class="alert alert-success">
              <strong>Success!</strong> Le film a bien été ajouté.
            </div>';
        } else {
            echo '
            <div class="alert alert-danger">
              <strong>Fail!</strong> Sorry, there was an error uploading your file.
            </div>';
        }
    }
}
?>

<body>