terryds Posted August 7, 2013 Share Posted August 7, 2013 What's the difference between require_once( dirname(__FILE__) . '/file.php'); and require_once('file.php'); Any difference ? Link to comment Share on other sites More sharing options...
Ingolme Posted August 7, 2013 Share Posted August 7, 2013 In the first case, it will load file.php from the directory that this file is in. In the second case, it will load file.php from the directory of the file that included this one. Here's an example: index.php <?php include 'files/a.php'; ?> files/a.php <?phpinclude 'b.php';include dirname(__FILE__) . '/b.php';?> b.php <?php echo 'This file was loaded from the root directory. '; ?> files/b.php <?php echo 'This file was loaded from the files directory. '; ?> If you run index.php it will output: This file was loaded from the root directory. This file was loaded from the files directory. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now