Toni
Toni

Reputation: 117

How can I remove the file path when using Glob()?

I just want to display the name of my images, without the path (../uploadedImages/)

<?php $images = glob("../uploadedImages/[kK]*.{jpg,png,gif,bmp}",GLOB_BRACE);   
foreach($images as $image) {echo "$image<br>"} ?>

Upvotes: 10

Views: 11067

Answers (2)

gstlouis
gstlouis

Reputation: 123

Although basename is good for a single file, if you need to cut the path for several files that glob gives as array, this way works great.

$contents = str_replace( __DIR__, '', glob( __DIR__ .'/*' ) );

Upvotes: 1

Explosion Pills
Explosion Pills

Reputation: 191829

Use basename

echo basename($image) . "<br>";

Upvotes: 24

Related Questions