Have you ever attempted to include a file for use in your document and it's not working? It's saying that it cannot find the file.
There's a simple solution to this issue.
chdir(dirname(__FILE__));
For PHP 5.3+
chdir(__DIR__);
Place it right above the require_once() or include() statement to set the path of the file relative to the document.
For example, lets say your folder structure is as follows:
classes/
config/
config.php
database/
database.php
You're currently in database.php and want to include config.php
You write your require_once("../config/config.php"); but it doesn't work. You get a Fatal Error.
Place the chdir(dirname(__FILE__)) right above the require statement to set the relative path to database.php
chdir(dirname(__FILE__));
require_once("../config/config.php");
For PHP 5.3+
chdir(__DIR__);
require_once("../config/config.php");
There's a simple solution to this issue.
chdir(dirname(__FILE__));
For PHP 5.3+
chdir(__DIR__);
Place it right above the require_once() or include() statement to set the path of the file relative to the document.
For example, lets say your folder structure is as follows:
classes/
config/
config.php
database/
database.php
You're currently in database.php and want to include config.php
You write your require_once("../config/config.php"); but it doesn't work. You get a Fatal Error.
Place the chdir(dirname(__FILE__)) right above the require statement to set the relative path to database.php
chdir(dirname(__FILE__));
require_once("../config/config.php");
For PHP 5.3+
chdir(__DIR__);
require_once("../config/config.php");
Comments
Post a Comment