dk007 dk007 - 1 year ago 97
PHP Question

php get webfolder address

i would like to know what PHP function/keyword i can use so that i can always get to the root of my webfolder. I'm using apache server with xampp.

I have a web folder by the name 'test1', so it's in the following path:

currently i'm using $_SERVRER['Document_Root'] to get the above information. I fear if i proceed with uploading this to an actual webserver the site might not work.

Is there a way where i can only get test1 so that when i create links, i don't need to worry about Document_Root

Answer Source

So you really want to get the base url which points to D:\xampp\htdocs\test1 or whatever subdirectory under D:\xampp\htdocs\ you wanna call it.

Now, i assume that in test1 directory there is an index.php file. If so, define a variable $base_url = dirname($_SERVER['PHP_SELF']);, it will return the full URL to your index.php file. You also might want to append a trailing slash to your $base_url

// Note

Maybe i misunderstood your requirements, i gave you a way to get the base url pointing to your index.php file under whatever sub-directory in D:\xampp\htdocs\. Now, talking about base directory, which is different, i would go around with something like:

$base_dir = dirname(__FILE__);

This variable would be defined into the index.php itself. Again, if you want to add a backslash/trailing slash (depending on the server environment). Append it like this:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download