PHP program to print the full path of the current program file

Here, we are going to learn how to print the full path of the current program file in PHP?
Submitted by Nidhi, on November 11, 2020 [Last updated : March 13, 2023]

Getting Full Path of Current Program File

Here, we print the full path of the current program file using magic constant __FILE__.

PHP code to get the full path of the current program file

The source code to print the full path of the current program using __FILE__ magic constant is given below. The given program is compiled and executed successfully.

<?php
//PHP program to print the full path
//of the current program file.

class Sample
{
    public function PrintProgramPath()
    {
        print (__FILE__ . "<br>");
    }
}

$S = new Sample();

$S->PrintProgramPath();
?>

Output

/var/www/prog.php

Explanation

In the above program, we created a class Sample that contains a function PrintProgramPath, here we printed the full path of the current program file using magic constant __FILE__, here we executed our program in ubuntu 18.04 operating system using apache server, then it will print appropriate path on the webpage.

PHP Class & Object Programs »



Related Programs



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.