AMIN Gholibeigian
AMIN Gholibeigian

Reputation: 337

Is there any function to return a relative path from public_html to the file location?

I need a function to return a relative path of the file , every where i run it. for example this is my code in "loc.php" :

<?
echo whereiam();
?>

outputs in these directories should be:

public_html/loc.php : /
public_html/folder1/folder2/loc.php : ../../

Is there any built-in function in php for this use?

Upvotes: 0

Views: 102

Answers (3)

Your Common Sense
Your Common Sense

Reputation: 157917

This is apparently wrong idea of doing something else.

There is no point in getting ../../ -style paths out of current location. You can (and should) use an absolute one.

Upvotes: 0

Ryan Kempt
Ryan Kempt

Reputation: 4209

The closest thing you're going to get is:

<?php
echo $_SERVER["SCRIPT_FILENAME"];
?>

EDIT: As for the second part of your script, I would probably do something like count the number of '/'s -1 in $_SERVER["SCRIPT_NAME"] and echo out that many ../'s? As far as I know there is no function that does something like this out of the box.

Upvotes: 0

Shakti Singh
Shakti Singh

Reputation: 86416

You can use __FILE__ magic constant.

echo __FILE__; 

Upvotes: 3

Related Questions