I was reading here about problems in PHP when using include() or required() with relative paths and all the solutions I saw was to append DIR
I’m currently working on Windows, and even though the error message displays the current value of DIR, then the relative path seems to be added as a string, rather than going one level up, for example:
include(__DIR__ . "..\\another_folder\\file_2.php");
produces the following error:
Warning: include(C:\xampp\htdocs\main_folder..\another_folder\file_2.php) [function.include]: failed to open stream: No such file or directory in
Any idea what’s going on?
You need to add the
\after the directory name:This will make the path be
instead of
Also, for portability, it is advisable to use
/instead of\, which works on all platforms, including Windows: