PHP – glob() Function to List and Filter Files in Folder

The glob() function in PHP allows you to search folders and put the results into an array based on basic filtering.

glob()

glob.php

<?php

$glob = glob("./folder/*");

print_r($glob);

echo "<br><br>";

foreach($glob as $file) {
    echo $file."<br>";
}

?>

glob.php (with Image Embed)

<?php

$glob = glob("./folder/*.jpeg");

print_r($glob);


echo "<br><br>";

foreach($glob as $file) {
    echo "<img src='".$file."'><br>";
}

?>

Be the first to comment

Leave a Reply