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
https://forums.phpfreaks.com/topic/95165-getting-file-path/
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
https://forums.phpfreaks.com/topic/95165-getting-file-path/#findComment-487452
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.