Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End PHP Problem – Dynamically loading images into a gallery

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #42481

    Hi guys and gals!

    I’m using some PHP code to dynamically pull images from a directory on a static site with no problems.

    When I try to alter the code to pull images from a directory in a WordPress installation, it fails.

    $dirArray[] = $entryName;
    }

    closedir($myDirectory);
    $indexCount = count($dirArray);
    echo $indexCount;
    ?>

    The end echo statement is just so I can see whether it’s populating the array or not. There is another loop statement to display the images, which I believe is fine. I just can’t get my head around why this doesn’t seem to be working.

    Is anyone able to help?

    #123373
    __
    Participant

    What is the value of `$tempDir`?

    Does your call to `opendir()` succeed?

    You might also be interested in PHP’s [`glob()`](http://php.net/glob) function.

    #123533

    Thanks for responding @traq.

    Umm… the first line is a $tempDir allocation, so that should be fine.
    I’m guessing it doesn’t succeed, as the array count is always 0. If I change $tempDir to a set path in a static site, the whole thing works fine. I think its the mixing of the template_url and relative path into a variable and then calling that variable that’s causing the issue, but I’m not certain.

    Had played around with glob() in the past, but once I got this working with opendir(), I moved on. Might have to go back and revisit.

    Any other ideas?

    #123559

    As it turns out, for anyone who is stuck with a similar issue:

    Replacing get_bloginfo(‘template_url’) with TEMPLATEPATH fixes the issue.

    #123565
    __
    Participant

    > the first line is a $tempDir allocation, so that should be fine.

    “should be,” sure. But you need to check. That function might be failing – you have no way to know unless you check.

    > Replacing get_bloginfo(‘template_url’) with TEMPLATEPATH fixes the issue.

    As a side note, you should avoid using URLs to access stuff on your own host. There’s no reason to open your front door, walk around the house, and come in through the back door just to get from the living room to your kitchen, right?

    :)

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘Back End’ is closed to new topics and replies.