简体   繁体   中英

Check if file exists on parent directory (from root) is impossible?

I was wondering why I can't check if file exists on parent directory (not from root and not from upper directories)

if(file_exists('../1.txt'))
{
    echo 'File Exists!';
}
else
{
    echo 'File Is Not Exists!';
}

Or is it impossible to check if file exists on parent directory ?

Today I ran into the same problem. I had a MVC handler within the folder

(app root)/mvc(/controller.php)

and wanted to go one folder up and then into the data folder to open an xml. My path was: "../data/foo.xml". It didn' work.

But then it came to me: Since I include the mvc/controller.php from the index.php in the app root, the controller "doesn't know" that it is located as an include in the root folder. And from there it simply has to be "data/foo.xml".

I'm not sure if this is your solution or if this is what you meant with "I was checking from 2 diff. locations", but I believe strongly, that for some devs who look up the problem's effect it could be the pebble to the solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM