software-engineers-workspace.jpg
PHP list images in current directory

PHP list images in current directory

To list all images in the current directory using PHP, you can use the glob function. Here’s an example of how you can use glob to get all the images from a folder:

<?php
define ('IMAGE_DIR', './');
foreach (glob (IMAGE_DIR.'*.{jpg,jpeg,png}', GLOB_BRACE) as $filename) {
    echo basename ($filename) . "<br>";
}
?>

This code will list all the images with extensions .jpg, .jpeg, and .png in the current directory. You can modify the IMAGE_DIR constant to list images in a different directory. I hope this helps!

This content was generated by Microsoft Bing. (source)

Was this helpful?
How was this post?
Subscribe to our newsletter
Stay updated on new releases and features, guides, and case studies. Get tips, technical guides, and best practices. Once a month. Right in your inbox.