How to check if a file exists under include path?

前端 未结 2 977
小鲜肉
小鲜肉 2021-02-19 16:45

You get the current include path in PHP by using get_include_path()

I am wondering what is the lightweight way to check if the file can be included without

2条回答
  •  南方客
    南方客 (楼主)
    2021-02-19 17:32

    As of PHP 5.3.2, you can use

    • stream_resolve_include_path — Resolve filename against the include path

    which will

    Returns a string containing the resolved absolute filename, or FALSE on failure.

    Example from Manual:

     var_dump(stream_resolve_include_path("test.php"));
    

    The above example will output something similar to:

     string(22) "/var/www/html/test.php"
    

提交回复
热议问题