View Full Version : Trouble navigating directory structure
JasonDFR
04-02-2009, 08: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, 03:23 PM
If the php file you are invoking is inside the application/ directory just "../data/logs.log" will do.
JasonDFR
04-02-2009, 04: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, 05: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, 05: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, 05: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 :)
vBulletin® v3.8.1, Copyright ©2000-2012, Jelsoft Enterprises Ltd.