Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: Warning: include failed to open stream no such file or directory on Windows [duplicate]

Tags:

include

php

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 the error message:

Warning: include(../config/eventInfoConfig.php) [function.include]: failed to open stream: 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 a relative path in my include without causing an error?

like image 733
user840930 Avatar asked Dec 15 '11 19:12

user840930


2 Answers

I would make it dynamic so that you can also include this file in other files and still have it work properly.

include_once(dirname(__FILE__).'/../config/eventInfoConfig.php');
like image 93
Soshmo Avatar answered Oct 10 '22 03:10

Soshmo


Fixing the include_path() to include the right path does the trick.

like image 20
greg0ire Avatar answered Oct 10 '22 04:10

greg0ire