如何使用glob从目录中获取图像 - 以前的帖子不起作用

如何使用glob从目录中获取图像 - 以前的帖子不起作用

问题描述:

I'm new to php and I'm trying to get a directory listing of images.
I saw this post: How to get random image from directory using PHP

I am trying to do nearly the same thing- choosing a random image and drawing it to the page via an tag.

For some reason, the specification to the directory that I am using doesn't work, but I'm not sure why. I've tried the following:

$localdir = $_SERVER['DOCUMENT_ROOT'] . '/wp_content/themes/overlandconsulting_2010/images/headers/*.{jpg,gif,png}';
$images = glob($localdir, GLOB_BRACE);

$httpdir = $_SERVER['SERVER_NAME'] . '/wp_content/themes/overlandconsulting_2010/images/headers/*.{jpg,gif,png}';
$images = glob($httpdir, GLOB_BRACE);

Neither seems to find any images. :s FWIW, I can navigate to the directory explicitly and see the contents, like this

It seems like the server won't let me access the images, but honestly I have no idea.

Thanks for any help! jml

the url in the code has wp_content with an underscore while the link to the directory has wp-content with a hyphen.