learningtech
learningtech

Reputation: 33695

The Script Path of an included PHP script?

Is there a way to achieve the following?

In my /www/var/public_html/index.php file i have this

<?php include('database/connect.php'); ?>

And then in /www/var/public_html/database/connect.php, I want to do something like this

<?php

$my_path = get_path_of_current_script(); // should not be path of index.php
echo $my_path;
// should print
// /www/var/public_html/database
?>

I don't want $my_path to print /www/var/public_html/

Is there a PHP function to do this?

Upvotes: 0

Views: 2641

Answers (1)

Pekka
Pekka

Reputation: 449485

$my_path = dirname(__FILE__);

Upvotes: 6

Related Questions