How to return just file name using glob() in php
Asked 07 September, 2021
Viewed 2.8K times
  • 52
Votes

How can I just return the file name. $image is printing absolute path name?

<?php
$directory = Yii::getPathOfAlias('webroot').'/uploads/';
$images = glob($directory . "*.{jpg,JPG,jpeg,JPEG,png,PNG}", GLOB_BRACE);
 foreach($images as $image)
   echo $image
?>

All I want is the file name in the specific directory not the absolute name.

7 Answer