How to display the image from a specified directory
How to display the image from a specified directory?
Displaying an image from a specified directory on a webpage is a common task in web development. Whether you want to showcase a gallery of images, profile pictures, or any visual content, it's essential to know how to retrieve and display images from a specific directory. In this guide, we will explore various methods to accomplish this task and provide step-by-step instructions to help you get started.
Step 1:
Create a file with in "PHP" format.
Ex: "index.php"
Step 2:
Apply PHP Loop function code. I'm using Bootstrap framework classes "row" and "col's"
<div class="row">
<?php
$files = glob("src/images/*.*"); // Image directory path
?>
<?php for ($i=0; $i<count($files); $i++) { $image = $files[$i]; ?> // PHP Loop Function code
<div class="col-lg-4 col-md-4 col-sm-6 col-6">
<img
src="<?php echo $image; ?>" // Print Function value in "img" tag under "src" attribute
class="w-100">
</div>
<?php } ?>
</div>
Output:
4th November 2023
Adarsh Vishwakarma
Share the Post
Feedback
Comment