doujing9972 2011-08-18 15:58
浏览 80
已采纳

如何使用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

  • 写回答

1条回答 默认 最新

  • doupin5408 2011-08-18 16:18
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法