saltcracker
saltcracker

Reputation: 321

Get Directory Name

I have this script that runs through all subdirectories of the directory images and prints out all the images.

<?php
    $dirname = 'images/*/';
    $images  = glob($dirname . "*");
    foreach ($images as $image) {
        echo '<img src="' . $image . '" class=image /><br>';
    }
?>

I also want to know the name of the subdirectories (the "*" in $dirname) where each image has been taken from so I can print it out.

So in the browser it should come out like this:

Upvotes: 1

Views: 46

Answers (1)

AbraCadaver
AbraCadaver

Reputation: 78984

Get the directory name and then get the trailing part of that:

echo basename(dirname($image));

Upvotes: 1

Related Questions