Q:

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

belongs to collection: PHP Classes & Objects Programs

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program/Source Code:

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.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

PHP Classes & Objects Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
PHP program to print the function name using magic... >>
<< PHP program to print the line number using __LINE_...