Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    New Zealand
    Posts
    127
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Absolute links in opendir()

    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:


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


    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?
    eTheory - the theory of revolution

  • #2
    Registered User
    Join Date
    Feb 2003
    Location
    Berkshire, UK
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •