Tuesday, 30 May 2023

PHP Code for photo gallery

 Here's an example of PHP code for a basic photo gallery:



<?php

// Array of image file names

$images = [

    'image1.jpg',

    'image2.jpg',

    'image3.jpg',

    // Add more image file names here

];


// Path to the directory containing the images

$imageDirectory = 'path/to/images/';


?>


<!DOCTYPE html>

<html>

<head>

    <title>Photo Gallery</title>

    <style>

        .gallery {

            display: flex;

            flex-wrap: wrap;

            justify-content: center;

            align-items: center;

        }

        .gallery-item {

            margin: 10px;

        }

        .gallery-item img {

            width: 200px;

            height: 200px;

            object-fit: cover;

        }

    </style>

</head>

<body>

    <h1>Photo Gallery</h1>


    <div class="gallery">

        <?php foreach ($images as $image): ?>

            <div class="gallery-item">

                <img src="<?php echo $imageDirectory . $image; ?>" alt="<?php echo $image; ?>">

            </div>

        <?php endforeach; ?>

    </div>

</body>

</html>

In this example, you need to provide the array $images with the file names of the images you want to display in the gallery. You also need to set the $imageDirectory variable to the path of the directory containing the images. The code will loop through the images and generate the HTML markup to display each image in a gallery format.

Remember to replace 'path/to/images/' with the actual path to your image directory.

This code will create a basic photo gallery that displays the images in a grid with a fixed width and height. You can modify the CSS styles to customize the appearance of the gallery according to your needs.

Copy Rights Digi Sphere Hub

No comments:

Post a Comment

How can I increase sales with SEO?

To increase sales with SEO ( Search Engine Optimization ), here are some effective strategies you can implement: Keyword research : Conduct ...