This commit is contained in:
thaaoblues 2023-07-02 20:08:35 +02:00
parent 5be236f92e
commit bb2507f786

View file

@ -18,54 +18,56 @@ if(isset($_POST['add_epreuve'])){
// 0 si une verification a invalidé le fichier // 0 si une verification a invalidé le fichier
// 2 si l'image existe déjà mais l'upload est valide, on va alors utiliser le nom pour la bdd // 2 si l'image existe déjà mais l'upload est valide, on va alors utiliser le nom pour la bdd
if(isset($_FILES["photo"])){
$EXT_WHITELIST = array("gif","jpg","jpeg","raw","png","svg");
$EXT_WHITELIST = array("gif","jpg","jpeg","raw","png","svg"); /* gestion des uploads d'images indices */
$target_dir = "../assets/img/com_ville/";
/* gestion des uploads d'images indices */ $target_file = $target_dir . basename($_FILES["photo"]["name"]);
$target_dir = "../assets/img/com_ville/";
$target_file = $target_dir . basename($_FILES["photo"]["name"]);
$upload_state = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
$check = $_FILES["photo"]["size"] > pow(2,2);;
if($check !== false) {
$upload_state = 1; $upload_state = 1;
} else { $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
$upload_state = 0; // Check if image file is a actual image or fake image
} $check = $_FILES["photo"]["size"] > pow(2,2);;
if($check !== false) {
if (file_exists($target_file)) { $upload_state = 1;
$upload_state = 2; } else {
} $upload_state = 0;
}
// limite de taille
if ($_FILES["photo"]["size"] > pow(2,25)) { if (file_exists($target_file)) {
$upload_state = 0; $upload_state = 2;
} }
// check le type de fichier // limite de taille
if (!in_array($imageFileType,$EXT_WHITELIST)){ if ($_FILES["photo"]["size"] > pow(2,25)) {
$upload_state = 0; $upload_state = 0;
} }
$file_name = ""; // check le type de fichier
switch($upload_state){ if (!in_array($imageFileType,$EXT_WHITELIST)){
case 1: $upload_state = 0;
}
move_uploaded_file($_FILES["photo"]["tmp_name"],$target_file);
$file_name = htmlspecialchars($_FILES["photo"]["name"]); $file_name = "";
break; switch($upload_state){
case 1:
case 2:
$file_name = htmlspecialchars($_FILES["photo"]["name"]); move_uploaded_file($_FILES["photo"]["tmp_name"],$target_file);
break; $file_name = htmlspecialchars($_FILES["photo"]["name"]);
case 0: break;
?> <script>
alert("L'image envoyée n'a pas passées tout les tests de vérifications."); case 2:
</script> $file_name = htmlspecialchars($_FILES["photo"]["name"]);
<?php break;
break; case 0:
?> <script>
alert("L'image envoyée n'a pas passées tout les tests de vérifications.");
</script>
<?php
break;
}
} }
$_POST['est_finale'] = $_POST['est_finale'] == 'on' ? true : false; $_POST['est_finale'] = $_POST['est_finale'] == 'on' ? true : false;