1

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?

1
  • It's very well possible that you've set up your include path in your Apache config file (or .htaccess). This will override set_include_path(). Comment out any "php_value include_path" type lines in your Apache conf file, and you should be able to set it now in your php code. Commented Jul 28, 2015 at 11:05

2 Answers 2

3

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) );
Sign up to request clarification or add additional context in comments.

2 Comments

Tried but still seems to find the file!
Initially I had the "FILE_USE_INCLUDE_PATH" in the wrong place - but I notice that if the file is in the same directory as the script running this code it finds the file regardless. I believe that is due, as @Mihai notes, the default values in php.ini. For example, on Windows the include path might be include_path=".;c:\php\includes" so it looks first at '.' - current directory!
1

In your php.ini config look for include_path which overrides the set_include_path function and commment it out then restart apache.

1 Comment

Thanks. One wonders what the point of set_include_path() is, then!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.