I need get full path to my web-project directory, as I am using single entry point so I doing this:
$_SERVER['SCRIPT_FILENAME']
then remove index.php
and then I get something like this: /var/www/myproject
, and then I can use it for require some stuff files like configuration etc. But when I call this method (e.g. for include some stylesheets) in my php files for rendering I getting 404 error for this stylesheet and what I getting in browser console:
http://localhost/var/www/myproject/bower_components/bootstrap/dist/css/bootstrap.min.css Failed to load resource: the server responded with a status of 404 (Not Found)
Obviosly that path should looks like:
http://localhost/myproject/bower_components/bootstrap/dist/css/bootstrap.min.css
So the question is how I can properly get path to my project for proper include files in PHP and load assets in HTML ? And the approach what I am using now it ok? Or I need to do somehow better? Thanks!
The problem is there are TWO type of adresses:
1) LOCAL, which are accessible throw your scripts from INSIDE your server. You use them if need to include file inside your script and such, but not from outside by browser.
2) WEB addresses, which are accessible by browser from OUTSIDE. You use them if need to give some file to browser, like style-sheet or JavaScript script.
Try $_SERVER['SERVER_NAME'] . $_SERVER["DOCUMENT_ROOT"]
for this task.
Detailed description for server environment variables