How do I format a PHP include() absolute (rather than relative) path?

前端 未结 9 940
情书的邮戳
情书的邮戳 2020-12-06 04:48

On various pages throughout my PHP web site and in various nested directories I want to include a specific file at a path relative to the root.

What single command c

9条回答
  •  Happy的楠姐
    2020-12-06 05:22

    If you give include() or require() (or the *_once versions) an absolute pathname, that file will be included. An absolute pathname starts with a "/" on unix, and with a drive letter and colon on Windows.

    If you give a relative path (any other path), PHP will search the directories in the configuration value "include_path" in order, until a match is found or there are no more directories to search.

    So, in short, to include an absolute filename, give an absolute filename. See also the function realpath().

    If you want to set your own include "root", have a look at this question (specifically my answer of course :-)

提交回复
热议问题