Test whether a file exists anywhere in the include path

后端 未结 5 2229
时光取名叫无心
时光取名叫无心 2021-02-20 12:25

I\'m writing an autoload function and in the inner logic of it would like to test whether a certain file exists somewhere in the path prior to including it.

This is the

5条回答
  •  眼角桃花
    2021-02-20 12:41

    I've written a function that can test it nicely

    function fileExists($file) {
        if(function_exists('stream_resolve_include_path'))
            return stream_resolve_include_path($file);
        else {
            $include_path = explode(PATH_SEPARATOR, get_include_path());
            foreach($include_path as $path)
                if(file_exists($path.DS.$file))
                    return true;
            return false;
        }
    }
    

提交回复
热议问题