Rocco The Taco
Rocco The Taco

Reputation: 3797

Remove directory from glob() results

I'm using the following PHP snippett to display all the pdf in a directory. How do I alter this code to still specify the directory BUT only display the filename?

foreach (glob("directory/sub-directory/sub-subdirectory/*.pdf") as $filename) {
    echo "$filename <BR>\n";
}

Upvotes: 2

Views: 1449

Answers (1)

Jonah Bishop
Jonah Bishop

Reputation: 12601

How about this:

$shortname = basename($filename);
echo "$shortname <BR />\n";

You would be making use of the basename function.

Upvotes: 4

Related Questions