Hi,
NOTE: wherever you see /localhost/ just imagine there is a "http:/" before it. This is because this forum doesn't allow you to enter a URL (even though strictly speaking it's not a URL you can access anyway) until you make 10 forum posts.
I'm building a PHP based website on my local machine and because I have other sites under my localhost I have to put them into folders (e.g. /localhost/SITENAME/).
The problem I'm having is with using absolute paths for my files (e.g. PHP include files, images, css, javascript).
I want to use absolute paths so I can move my PHP web pages into sub folders (e.g. /localhost/SITENAME/PRODUCT-NAME/).
The problem is that I have to manually type into each and every file path "/SITENAME/" at the start, because if I use just a forward slash / then it will try to find the file here: "/localhost/".
I've tried usingbut that doesn't work as expected?PHP Code:$_SERVER['DOCUMENT_ROOT']
I want to be able to use something like a PHP SERVER variable that can find the root of the website folder and so when I upload the site to the live server I don't have to change any code because the PHP variable will detect the new server root.
Some of the $_SERVER variables show C:\ rather than /SITENAME/ and others such as $_SERVER['SCRIPT_FILENAME'] or $_SERVER['PHP_SELF'] show both the sub folder and the current file name (e.g. /localhost/SITENAME/PRODUCT-NAME/index.php) and it seems like it would be a server resource hog to have to call a function which explodes the string into an Array and then just use the relevant part of the URL that I need, but also that it might not work then as expected when putting the site on the live server and so again I have to change the original code which is something I want to avoid.
Any help greatly appreciated as I'm sure there is a fairly simply solution.
Kind regards,
M.










Bookmarks