PHP: warning: enable failed to open stream no such file or directory in Windows

I have an include statement in a PHP script running on xampp on Windows. If I use a relative path:

include '../config/eventInfoConfig.php';  

I get an error message:

Warning: include (../config/eventInfoConfig.php) [function.include]: could not open the stream: there is no such file or directory

But if I use the absolute path, I have no error:

include 'c:/xampp/htdocs/xampp/appTrials/myApp/config/eventInfoConfig.php'; 

How can I use the relative path in my inclusion without causing an error?

+5
source share
3 answers

Committing include_path()to enable the correct path does the trick.

+2
source

, .

include_once(dirname(__FILE__).'/../config/eventInfoConfig.php');
+3

You can turn a relative path into an absolute one. includecomplicated. I always just save the global constant, BASE_PATHwhich contains the absolute path, and add the file I need to include.

+1
source

All Articles