Reputation: 11240
I am running a homebrew install of php and nginx. My root web directory is /var/www. Inside that I have a folder with a bunch of files:
rmp:~ rmp$ cd /var/www/somefolder
rmp:somefolder rmp$ ls
//lists all the files
I made a script to loop through the directory and do something with the files:
$dir = new DirectoryIterator(dirname('/var/www/somefolder/'));
foreach ($dir as $fileinfo) {
if (!$fileinfo->isDot()) {
var_dump($fileinfo->getFilename());
}
}
Instead of getting all the filenames in somefolder/ folder, I'm getting a list of files in /var/www
I thought that it's strange, so I tried a relative path instead, since my script is in a folder paralell to somefolder I tried path:
$dir = new DirectoryIterator(dirname('../somefolder/'));
Again, contents of /var/www
The problem seems elementary. Making me feel really stupid.
I thought maybe the server thinks I'm in a different directory? I tried echo getcwd()
and got /private/var/www
So I also tried everything with absolutes with private prepended as well. Still the same. What have I missed?
Here's the weird thing, if I make the path:
/var/www/somefolder/somefolder
Then it works!? It shouldn't. Any ideas?
Upvotes: 0
Views: 301
Reputation: 51
because dirname('/var/www/somefolder/') result is '/var/www',you can test it.
Upvotes: 1