Hello
Is there a way to get access to the full path for the file my code is in?
For example, if I have 2 files:
c:\a.php
c:\innerFolder\included.php
page a.php includes file included.php like so:
require_once('c:/innerFolder/included.php');
now if I am in included.php, I need a code that will give me its full path: 'c:/innerFolder/included.php'
if I am in a.php, I need the file path: 'c:/a.php'
I need to write a code that outputs the name of the file and I will put it at the top of all my files in the project
I need to use it to know through what files my script is passing
thanks
getting access to the name of the file the code is in
Moderator: General Moderators
Important: I need an automatic solution as I even though my example has 2 files, my actual code has thousands of files so it is not practical to modify each and every one of them. I need some how to make sure that the following code is injected at the beginning of EACH of my .php files in the project:
I don't want to take this code and to copy-paste it at the beginning of EVERY file
I need a solution that will take that code and will implicitly inject it in runtime to every .php file
I have thousands of files and I cannot litter them with such code which should be defiend only once in a single place in the application
I need a solution that doesn modify ANY of my files
Mabye a solution that automatically injects this code implicitly by apache or by modifying php.ini
Code: Select all
if (!isset($fileNameHandle)) {
$fileNameHandle = fopen($_SERVER['DOCUMENT_ROOT'] . '/logs/' . files.txt', "at+");
}
// get path to the file here
fwrite($fileNameHandle, __FILE__ . "\n");I need a solution that will take that code and will implicitly inject it in runtime to every .php file
I have thousands of files and I cannot litter them with such code which should be defiend only once in a single place in the application
I need a solution that doesn modify ANY of my files
Mabye a solution that automatically injects this code implicitly by apache or by modifying php.ini
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Thanks Jenk
Your tip was very helpful
I can just add the following snippet at the bottom of every file I want to test:
This doesn't polute unneeded files
Your tip was very helpful
I can just add the following snippet at the bottom of every file I want to test:
Code: Select all
$includedFiles = get_included_files();
$fileNameHandle = fopen($_SERVER['DOCUMENT_ROOT'] . '/logs/' . 'files.txt', "at+");
foreach ($includedFiles as $filename) {
fwrite($fileNameHandle, $filename . "\n");
}
fclose($fileNameHandle);