Results 1 to 6 of 6

Thread: Trouble navigating directory structure

  1. #1
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default Trouble navigating directory structure

    PHP Code:

    // What I want does NOT work:
    file_get_contents('/home/user/subdomains/test2/application../data/logs/log.log');
    // In reality /home/user/subdomains/test2/application gets replaced with APPLICATION_PATH

    // The absolute path to what I want does work:
    file_get_contents('/home/user/subdomains/test2/data/logs/log.log'); 
    My application path is defined, so I'd like to navigate up to the parent directory and then into data/logs/ etc. /application and /data are in the same directory. In this case /home/user/subdomains/test2
    Last edited by JasonDFR; 04-02-2009 at 07:49 AM.

  2. #2
    Join Date
    Mar 2009
    Posts
    65
    Thanks
    13
    Thanked 4 Times in 4 Posts

    Default

    If the php file you are invoking is inside the application/ directory just "../data/logs.log" will do.

  3. #3
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default

    Code:
    /home/user/subdomains/test2/application../../data/logs/log.log
    OR

    PHP Code:
    APPLICATION_PATH "../../data/logs/log.log" 
    OR


    PHP Code:
    APPLICATION_PATH "../../$config->logfile
    is what ended up working. I always get confused when trying to write these out. Does anyone have any tricks for making it easier to figure out?

    Since /application and /data are on the same level my instinct was to use "../" to leave /application and then go directly into /data. I'm not sure why I am having to use "../../"

    Please advise.

  4. #4
    Join Date
    Mar 2009
    Posts
    65
    Thanks
    13
    Thanked 4 Times in 4 Posts

    Default

    Edit: misread your questions so I removed a large chunk of text

    Just curious. Does this work?

    PHP Code:
    /home/user/subdomains/test2/application/../data/logs/log.log 

  5. #5
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default

    PHP Code:
    $f file_get_contents('/home/user/subdomains/test2/application/../data/logs/log.log');
    echo 
    $f
    Yes, this works. So what is the trick?

    I guess initally I was forgetting the / slash after application..

  6. #6
    Join Date
    Mar 2009
    Posts
    65
    Thanks
    13
    Thanked 4 Times in 4 Posts

    Default

    Quote Originally Posted by JasonDFR View Post
    PHP Code:
    $f file_get_contents('/home/user/subdomains/test2/application/../data/logs/log.log');
    echo 
    $f
    Yes, this works. So what is the trick?

    I guess initally I was forgetting the / slash after application..
    Yes. I think so. Originally, your filepath is not valid. A directory should always end with a / so the original /home/user/test2/application../data...." didn't work because the application part must end with a / for it to be a valid file-path.

    So the filepath has a syntax error, so to say

Bookmarks

Posting Permissions

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