简体   繁体   English

检查父目录(从root)上是否存在文件是不可能的?

[英]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) 我想知道为什么我无法检查父目录中是否存在文件(不是来自root而不是来自上层目录)

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 我在文件夹中有一个MVC处理程序

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

and wanted to go one folder up and then into the data folder to open an xml. 并想要一个文件夹,然后进入数据文件夹打开一个xml。 My path was: "../data/foo.xml". 我的路径是:“../ 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. 但后来它告诉我:由于我在app根目录中包含了index.php中的mvc / controller.php,因此控制器“不知道”它位于根文件夹中的include。 And from there it simply has to be "data/foo.xml". 从那里它只需要是“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. 我不确定这是否是你的解决方案,或者这是你的意思“我正在检查2个差异位置”,但我强烈相信,对于一些看起来问题影响的开发者来说,它可能是解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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