Jump to content

What's the difference between using dirname and not


terryds

Recommended Posts

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...