10

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>"} ?>
1
  • If you chdir(), you can omit the path from the result strings. Commented Oct 6, 2022 at 10:49

2 Answers 2

24

Use basename

echo basename($image) . "<br>";
Sign up to request clarification or add additional context in comments.

1 Comment

If you just need an array of files: $files = array_map('basename', $files);
1

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__ .'/*' ) );

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.