How do I get all images within Wordpress Uploads directory, then display all?

I'm trying to get all of the images inside a specific sub-directory within the Wordpress uploads directory, and then output all of those images.

$upload_dir = wp_upload_dir(); 
$logo_dir = ( $upload_dir['baseurl'] . '/logos/' );
echo $logo_dir . '-----<br />';
$images = glob($logo_dir . "*.PNG");
foreach($images as $image)
{
   echo $image;
}

$logo_dir is outputting the correct directory. I'm not sure what I'm doing wrong with the foreach.

Any help? Thanks!

Upvotes: 3

Views: 4058

Answers (1)

Pedro Lobito
Pedro Lobito

Reputation: 98901

Change:

$logo_dir = ( $upload_dir['baseurl'] . '/logos/' );

to

$logo_dir = ( $upload_dir['basedir'] . '/logos/' );

https://codex.wordpress.org/Function_Reference/wp_upload_dir


Update based on your comments:

foreach($images as $image)
{
$filename = basename($image);
echo $upload_dir['baseurl']."/$filename";
}

Upvotes: 1

Related Questions