Jump to content

Path of the file, inside a subdirectory, that is called by an include


Recommended Posts

Hello all,

 

I have the following directory structure from root:

./

./Subdir/

 

Inside "./Subdir/", I have the file "file_subdir.php" with code:

<?php
echo $_SERVER['PHP_SELF'];
?>

 

Inside "./", I have the file "file_root.php" with code:

<?php
include('./Subdir/file_subdir');
?>

 

If I run "file_subdir.php", I get the output:

./Subdir/file_subdir.php

 

And if I run "file_root.php", I get the output:

./file_root.php

 

What I want is the output of file "file_root.php" to be the path of the file pointed by the include (since the code is inside that include), i.e., I want the output of "file_root.php" to be:

./Subdir/file_subdir.php

 

How can I do it?

A list of all server variables: http://www.php.net/manual/en/reserved.variables.server.php

 

have you tried using $_SERVER['SCRIPT_FILENAME'];?

 

check out that manual page and see if one of those will work

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.