How do you get PHP, Symlinks and __FILE__ to work together nicely?

前端 未结 6 1688
既然无缘
既然无缘 2020-12-02 15:19

On localhost. I have the following directory structure:

/share/www/trunk/wp-content/plugins/otherfolders

/share/www/portfolio/wp-content/s

6条回答
  •  爱一瞬间的悲伤
    2020-12-02 16:19

    If I were trying to solve this, I'd split __FILE__ along the path bits and create a SplFileInfo for each along the way, test with isDir and isLink, then try to determine how to handle reconstruction of the path once it's known to be different than expected so you can pull from the right directory. (If you're more of a procedural type, there's is_dir and is_link.)

    That being said, I think you've already disqualified this solution. Maybe the tools are smart enough to do it for you. Try comparing the result of getRealPath to getPath? getRealPath expressly says that it resolves symlinks, while getPath doesn't expressly say that.

    Even then, this sniffing might not be safe on client sites, depending on who the host is. I've seen some pretty creative shared hosting filesystem setups. You could add a check to php_uname and pull out the hostname of the machine, and if it isn't your dev box, don't do the extra work.

提交回复
热议问题