This content originally appeared on CodeSource.io and was authored by Ariessa Norramli
In this article, you will learn how to make a simple photo gallery in PHP.
Simple Photo Gallery
In order to make a simple photo gallery, you can use the glob()
method, GLOB_BRACE
flag and basename()
method.
<?php
// Path to folder that contains images
$path = "C:/xampp/htdocs/gallery/";
// Get files that ends with either jpg, jpeg, png from $path
$images = glob("$path*.{jpg,jpeg,png}", GLOB_BRACE);
// Display images in a photo gallery
foreach ($images as $i) {
printf("<img src='gallery/%s'/>", basename($i));
}
?>
Result
Note: The glob()
method functions by searching for path names that match the supplied pattern. The GLOB_BRACE
flag functions by expanding options in the curly braces. In this example, GLOB_BRACE
looks for a path that ends with either jpg, jpeg, or png. The basename()
method functions by returning the file name from the supplied path.
The post How to Make Simple Photo Gallery in PHP appeared first on CodeSource.io.
This content originally appeared on CodeSource.io and was authored by Ariessa Norramli

Ariessa Norramli | Sciencx (2021-03-06T05:12:00+00:00) How to Make Simple Photo Gallery in PHP. Retrieved from https://www.scien.cx/2021/03/06/how-to-make-simple-photo-gallery-in-php/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.