简体   繁体   中英

PHP include path: what am I doing wrong?

OK I'm quite sure this is the easiest question someone out there will ever answer.

I try to get and echo the contents of a file in the same level:

die(file_get_contents('test.txt')); //"hello"

Works fine. I try to invalidate that call by setting a bad include path:

set_include_path('non-existant-dir');
die(file_get_contents('test.txt')); //still "hello"

...but it still finds the file. Shouldn't set_include_path mean the call to file_get_contents looks for test.txt in a dir called non-existant-dir , and thus fail?

The function "file_get_contents" can take several arguments - one of which is a combination of flags where one such flag is "FILE_USE_INCLUDE_PATH" - by default I don't think it will use the include path so it makes no difference what you set the include path to. Try:

set_include_path('non-existant-dir');
die( file_get_contents('test.txt', FILE_USE_INCLUDE_PATH) );

在您的php.ini配置中,查找include_path ,它会覆盖set_include_path函数并对其进行set_include_path ,然后重新启动apache。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM