PHP - 系统找不到指定的路径。 (但它从另一个文件中找到它)
My main app is at:
'.app/index.php'
What I do from there is parse a directory
foreach (new DirectoryIterator('./app/uploads/images/') as $fileInfo) {
if($fileInfo->isDot()) continue;
$images[] = $fileInfo->getFilename();
}
And it works ok.
But, when I do the exact same thing from
'./app/models/tricky.php'
I get the error from the title.
Any clue what I'm doing wrong?
I also tried modifying path to '../app/uploads/images/'
but have no clue what else to do.
Thanks.
我的主应用程序位于: p>
'。app / index.php'
code> pre>
我从那里做的是解析一个目录 p>
foreach(new DirectoryIterator(' ./app/uploads/images/')as $ fileInfo){
if($ fileInfo-> isDot())continue;
$ images [] = $ fileInfo-> getFilename();
} \ n code> pre>
它运作正常。 p>
但是,当我从 p>
做同样的事情时
'./ app / models / tricky.php'
code> pre>
我从标题中收到错误。 p>
我知道我做错了什么? p>
我也尝试修改'的路径../ app / uploads / images /' code>
但是 不知道还能做什么。 p>
谢谢。 p>
div>
The difference and simple problem is:
You're two scripts are not in the same directory. If you use the './directory' notation, the '.' means starting at your current directory which is one time 'app' and the other time 'app/models/'.
Solve the problem by changing the path string in 'app/models/tricky.php' to '../uploads/images/'. The double dot '..' is important, it stands for the parent directory (go one directory up).
Depending on how you have your routing set up, does:
'./app/index.php/models/tricky.php'
produce a result?
Also, you might implement:
is_dir('app/models/');
and see what you get (it'll produce a boolean value.
Let me know the results and perhaps that'll lead us somewhere helpful.