Jump to content

Getting file path.


xenophobia

Recommended Posts

Alright let go to the problems here:

 

Let say I got a php file: file_1.php with the following simple code:

<?php
includes("mypath/file_2.php");
?>

 

Lets say in file_2.php :

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

 

As you can see, it is very simple. The file_1.php will include one file from the mypath directory called file_2.php.

 

So when I run the file_1.php, the output will be:

file_1.php

 

So how am I going to print /mypath/file_2.php since the output (echo) function are invoke in file_2.php.

 

Thanks.

Link to comment
Share on other sites

include or require does NOT execute the included file in it's path, so you will hvae another way to do this...

 

- enter the path manually. you may use str_replace() to replace the pathes with the one you choosed, this is better in my opinion...

 

- use fopen() to a file_1.php file rather than include and read the first line ( refere to file read usage for more info ), and without changes in file_2.php. in this case the server will execute file_2.php in it's path then give the results to file_1.php

Link to comment
Share on other sites

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.