I am a beginner in PhP and I am doing an image gallery with PhP (to facilitate the construction of the div that contains the images and applies the styles).
This is the code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<title>Prueba de codigo</title>
</head>
<body class="bg-info">
<section class="container-fluid">
<div class="row justify-content-center">
<div class="col-12 text-center">
<h1 class="text-white mt-5">Galería de imágenes</h1>
</div>
</div>
<?php
$directorio = opendir("images"); //ruta actual
while ($archivo = readdir($directorio)) //obtenemos un archivo y luego otro sucesivamente
{
if (is_dir($archivo))//verificamos si es o no un directorio
{
//Aqui se hace algo si no es un directorio, opcional
}
else
{
//Aqui hacen lo que quieran con cada archivo
echo "<div class='row justify-content-center'>";
echo "<div class='col-xs-12 col-sm-12 col-md-8 col-lg-8 text-center'>";
echo "<div class='card-columns'>";
echo "<div class='card'>"; //card con imagen
echo "<a href='#' data-toggle='modal' data-target='#modal_img'>";
echo "<img src='images/$archivo' alt='$archivo' class='card-img-top' />";
echo "</a>"; //cierre link imagen
echo "</div>"; //cierre card
echo "<div class='modal fade' id='modal_img' tabindex='-1' role='dialog' aria-labelledby='exampleModalLabel' aria-hidden='true' style='z-index: 2000;'>"; //modal de imagen centrada
echo "<div class='modal-dialog modal-lg modal-dialog-centered' role='document'>";
echo "<img src='images/$archivo' alt='$archivo' class='img-fluid rounded' />";
echo "</div>"; //cierre modal dialog
echo "</div>"; //cierre modal fade
echo "</div>"; //cierre card columns
echo "</div>"; //cierre columna
echo "</div>"; //cierre row
}
}
?>
</div>
</div>
</section>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>
The code itself works for me, but I have 2 problems that can not be solved:
1) I try to make them occupy the structure that I gave with the bootstrap 4 but it does not work, I have the images one below the other, and I want them to be ordered sideways first. If I use that gallery model only as HTML it works for me without problems.
2) When I click on the modal, I always see only the first image, and obviously I would like it to show the image I click, I have no idea how to do that.
I'm trying to make it look like this:
Once again Thanks to the whole community.