View Full Version : Absolute links in opendir()

04-16-2003, 03:40 PM
I have an include which counts how many files are in a directory and displays one of them at random.

Part of my code includes this:

$h = opendir('images/ads/');
while (false !== ($file = readdir($h))) {
if ($file != "." && $file != "..") {

If a file is in a sub-directory then I need to use a completely different include which has opendir('../images/ads/'); and so on through the directories.

Is there a way to tidy this up so that I can use a single include for all my pages no matter which directory it is in?

04-16-2003, 04:36 PM
you can use the entire length of the path.

e.g. home/apache/httpdocs/whatever/images/ads/

which should work anywhere... although i dunno if there's any easier options for you.