PHP: open_basedir allowed path

≡放荡痞女 提交于 2019-12-05 10:37:43

There is unfixed bug in PHP that is triggered when you open or check a path that have an existent file as prefix, and not existent part as suffix. In your example there is existent part /home/virtual/domain.com/public_html/galleries/img/002.JPG with not existent suffix / (trailing slash in path).

There is explanation that this is not a bug: “This is expected behaviour. A non path that doesn't exists (the one with the slash) is considered outside of the basedir.”, but I don't think so. This bug only triggers if first part of path is an existent file.

PHP bugs:

Turns out the answer was super simple, yet completely illogical:

When creating (concatenating) the paths to iterate through, I had for some reason hard-coded a trailing slash—note how the path above ends in img/002.JPG/ with a slash at the end. Removing this slash fixed the error. This also explains why it didn’t fail on directories (which are supposed to have trailing slashes), only files (which aren’t).

Going by what the PHP documentation says, is_dir() should return TRUE if the path specified represents an existing directory; and FALSE in all other cases, including if the file specified does not exist (which img/002.JPG/ doesn’t).

So I’m still a bit puzzled as to why it didn’t just return FALSE the way it used to in PHP 5.2, but instead makes this rather abstruse and frankly just downright wrong statement that the file is not within the allowed path … but at least it works again now.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!