View Full Version : Trouble navigating directory structure
JasonDFR
04-02-2009, 07:42 AM
// 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
CrazyChop
04-02-2009, 02:23 PM
If the php file you are invoking is inside the application/ directory just "../data/logs.log" will do.
JasonDFR
04-02-2009, 03:56 PM
/home/user/subdomains/test2/application../../data/logs/log.log
OR
APPLICATION_PATH . "../../data/logs/log.log"
OR
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.
CrazyChop
04-02-2009, 04:10 PM
Edit: misread your questions so I removed a large chunk of text
Just curious. Does this work?
/home/user/subdomains/test2/application/../data/logs/log.log
JasonDFR
04-02-2009, 04:23 PM
$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..
CrazyChop
04-02-2009, 04:41 PM
$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 :)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.