如何使用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
我是php的新手,我正在尝试获取图像的目录列表。 我试图做几乎相同的事情 - 选择随机图像并通过标签将其绘制到页面上。 p>
For 某些原因,我使用的目录的规范不起作用,但我不知道为什么。 我尝试了以下内容: p>
似乎都没有找到任何图像。 :s
FWIW,我可以显式导航到该目录并查看内容,例如
这个 p>
似乎服务器不允许我访问图像,但老实说我不知道。 p>
感谢您的帮助!
jml p>
div>
看到这篇文章:如何使用PHP从目录中获取随机图像 p>
$ 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);
code> pre>
the url in the code has wp_content
with an underscore while the link to the directory has wp-content
with a hyphen.