Bonjour à tous,
J'ai mis en place un upload de fichier par lequel j'autorise uniquement l'upload d'images en JPG.
Bizarrement lors de l'upload de certains fichiers hors extensions autorisées, au lieu de tomber sur le warning "LE FORMAT DE VOTRE FICHIER N'EST PAS AUTORISÉ", je tombe soit sur le warning "VOUS AVEZ OUBLIÉ DE RENSEIGNER LA LÉGENDE" (ligne 8), soit sur le warning "VOUS AVEZ OUBLIÉ DE JOINDRE UN FICHIER" (ligne 67)...???
(Je précise que dans les 2 cas le fichier ET la légende sont bien renseignés).
Cela se produit avec les extensions mov, mp4, mpeg3 (et peut-être d'autres que je n'aurais pas testées...).
Dans le lot que j'ai testé, les extensions wmv, pdf, xls et png déclenchent bien le bon warning.
Où se cache l'erreur dans mon code ??
Quelqu'un aurait-il une idée ?
Merci par avance.
Le formulaire
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 <form id="uploadPhotos" method="post" action="traitement_photo.php" enctype="multipart/form-data"> <div id="choixPhoto"> <div id="etiqBoxUploadPhoto">Choisissez une photo :</div> <div> <input type="file" name="boxUploadPhoto" id="boxUploadPhoto" required /> </div> </div> <div id="legendePhoto"> <div id="etiqLegendePhoto">Rédigez une légende :</div> <textarea name="txtLegendePhoto" id="txtLegendePhoto" maxlength="200" required></textarea> </div> <div id="envoyerPhoto"> <input type="submit" id="champValidPhoto" value="ENVOYEZ" /> </div> </form>
traitement_photo.php
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 <?php require "connect.php"; if (empty($_POST['txtLegendePhoto'])){ echo "<p class=\"warningTraitement\">VOUS AVEZ OUBLIÉ DE RENSEIGNER LA LÉGENDE<br /><a href=\"javascript:history.go(-1)\">Retour à la page précédente</a></p>"; } else{ if (isset($_FILES['boxUploadPhoto']) AND $_FILES['boxUploadPhoto']['error'] == 0){ if ($_FILES['boxUploadPhoto']['size'] <= 100000000){ $infosfichier = pathinfo($_FILES['boxUploadPhoto']['name']); $extension_upload = $infosfichier['extension']; $extensions_autorisees = array('jpg', 'jpeg', 'JPEG', 'JPG'); if (in_array($extension_upload, $extensions_autorisees)){ $nom = md5(uniqid(rand(), true)); $nomext = $nom.".".$extension_upload; $destination = 'uploadPhoto/'; $chemin = $destination.$nom.".".$extension_upload; move_uploaded_file($_FILES['boxUploadPhoto']['tmp_name'], 'uploadPhoto/' . $nom.".".$extension_upload); $req = $bdd->prepare('INSERT INTO photos(nomPhoto,legendePhoto) VALUES(:nomPhoto, :legendePhoto)'); $req->execute(array( 'nomPhoto' => $nomext, 'legendePhoto' => $_POST['txtLegendePhoto'], )); $req->closeCursor(); echo "<p class=\"validationTraitement\">MERCI POUR VOTRE PHOTO</p>"; } else{ echo "<p class=\"warningTraitement\">LE FORMAT DE VOTRE FICHIER N'EST PAS AUTORISÉ<br /><a href=\"javascript:history.go(-1)\">Retour à la page précédente</a></p>"; } } else{ echo "<p class=\"warningTraitement\">LA TAILLE DE VOTRE FICHIER DÉPASSE LA LIMITE AUTORISÉE<br /><a href=\"javascript:history.go(-1)\">Retour à la page précédente</a></p>"; } } else{ echo "<p class=\"warningTraitement\">VOUS AVEZ OUBLIÉ DE JOINDRE UN FICHIER<br /><a href=\"javascript:history.go(-1)\">Retour à la page précédente</a></p>"; } } ?>
Partager