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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| <?php
$db = mysqli_connect("localhost", "root", "", "mydb");
if(!empty($_FILES)){
require("imgClass.php"); // Classe pour miniaturiser la photo
$img = $_FILES['img'];
$ext = strtolower(substr($img['name'], -3));
$allow_ext = array('jpg','png');
if(in_array($ext,$allow_ext)) {
move_uploaded_file($img['tmp_name'], "images/".$img['name']); // Enregistrement de la photo dans le dossier principal (sans muniature) /fonctionnement tres bien
Img::creerMin("images/".$img['name'],"images/art_min",$img['name'], 225,225); // Enregistrement de la même photo dans le sous-dossier du dossier principal mais cette fois si muniaturisée /fonctionnement tres bien
$img =$_POST['tmp_name']."images/".$img['name'];
$noms = $_POST['noms'];
$sql = "INSERT INTO agent (noms, photo) VALUES ('$noms', '$img')"; // Pour le nom c ok mais la photo c vide
mysqli_query($db, $sql);
}
else{
$erreur = "Attention!! Votre fichier n'est pas une image";
}
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Document sans nom</title>
</head>
<body>
<?php
if (isset($erreur)) {
echo $erreur;
}
?>
<form method="post" action="uploader.php" enctype="multipart/form-data">
<input type="file" name="img"/>
<input type="text" name="noms"/>
<input type="submit" name="Envoyer"/>
</form>
<?php // Partie affichage sur l'ecran, fonctionnement OK
$doc = "images/art_min";
$dir = opendir($doc);
while ($file = readdir($dir)) {
$allow_ext = array('jpg','png');
$ext = strtolower(substr($file, -3));
if(in_array($ext, $allow_ext)){
?>
<a href="images/<?php echo $file; ?>">
<img src="images/art_min/<?php echo $file ?>"/>
<h3><?php echo $file ?></h3>
</a>
<?php
}
}
?>
</body>
</html> |
Partager