Pim
Pim

Reputation: 123

Root of website in a subdirectory in PHP

I'm developing a website in PHP. The test environment is in a subdirectory of the root and there are multiple test environments. But the website doesn't work properly because of al the absolute and also the relative paths. So i need a clean solution to get the path of the root of the website and not of the server.

I've tried a lot of thinks but nothing seems to work.

I hope you have a beter solution for this problem.

Thanks in advance!

Upvotes: 0

Views: 92

Answers (2)

Jan.J
Jan.J

Reputation: 3080

Not sure if this will help, but if you want to get directory of current php file you should use __DIR__ constant. More info here.

If your website index is located at /home/www/subpath/index.php, this code in index.php:

echo __DIR__;

will return:

/var/www/subpath

Upvotes: 1

Deus Levin
Deus Levin

Reputation: 193

You can use a SESSION to set your desired PATH and use it on all the path you need.

If you are using a framework like Laravel this can be done a lot easier.

Upvotes: 0

Related Questions