Afficher les images sur une page si le fichier existe ou pas
Bonsoir, j'ai un message d'erreur sur la page =>
Citation:
( ! ) Remarque : Index non défini : nom du fichier dans C:\wamp64\www\projet-images\contenu.php à la ligne 19 Call Stack #TimeMemoryFunctionLocation 10.0001361032{main}( )...\index.php : 0 20.0028411064require( ' C:\wamp64\www\projet-images\contenu.php )...\index.php : 8">
class/imageManager.php
Code:
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
|
class imageManager {
private $db;
public function __construct($db) {
$this->setDb($db);
}
public function setDb(PDO $dbh) {
return $this->db = $dbh;
}
public function getImagesData() {
try {
$sql = 'SELECT id, title, descr, filename FROM images';
$stmnt = $this->db->prepare($sql);
$stmnt->execute();
while($row = $stmnt->fetch(PDO::FETCH_ASSOC)) {
$path = IMAGE_DIR_PATH . $row['filename'];
if(file_exists($path)) {
$image_data[$row['id']]['id'] = $row['id'];
$image_data[$row['title']]['title'] = $row['title'];
$image_data[$row['descr']]['descr'] = $row['descr'];
$image_data[$row['filename']]['filename'] = $row['filename'];
$image_data[$row['id']]['exist'] = 'OK';
}
}
echo '<pre>';
print_r($image_data);
echo '</pre>';
return $image_data;
}
catch(PDOException $e) {
echo 'Une erreur est survenue lors de la récupération des données dans la base. ' . $e->getMessage();
}
} |
contenu.php
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
<?php
$manager = new imageManager($db);
$images = $manager->getImagesData();
?>
<h1><?php echo WEB_TITLE ?></h1>
<ul>
<?php if(!empty($images)) : ?>
<?php foreach($images as $image) : ?>
<li>
<p><img src="<?php echo $image['filename'] ?>"></p>
<p><?php echo $image['title'] ?></p>
<p><?php echo $image['descr'] ?></p>
</li>
<?php endforeach ?>
<?php endif ?>
</ul> |
Merci d'avance.