Hello--- This is probably a very newbish question, so please bear with me. How can I get the "web directory" of the program? ie. If I have a script running in "localhost/test/inc/test.php", how can I retrieve the value "localhost/test"? I hope that makes sense. Please let me know if it doesn't, or if you need anymore information. Thank you in advance for your help!
try echo $_SERVER["SCRIPT_NAME"]; this will output something like this test/inc/test.php you will need to use explode function get the correct information form the output
If you've opened /includes/system/config.php, it will say that your path is /includes/system/ : <?php function getScriptPath() { $self = $_SERVER['PHP_SELF']; preg_match('/(.*)\/[a-zA-Z0-9.php]/', $self, $path); $full_path = $path[1] . "/"; return $full_path; } ?> PHP: Another easy way to get your current file & path : <?php $file_and_path = __FILE__; echo $file_and_path; ?> PHP:
And once you have __FILE__ , dirname() will strip a file/directory name off the right side. e.g., echo dirname(dirname(__FILE__)); Code (markup): will get you what you're after in this case.
Thank you everyone for your suggestions! However, I didn't quite type what I wanted right ( I was really tired..... ) I am looking for something where if the script is running in "http://localhost/test/inc/test.php", to get the "http://localhost/test" part. (I left out the http:// ) Any ideas on how to get that? Once again, thank you all for your help!
I got it. Thank you to everyone for their help. I modified ActiveFrost's script a slight bit. Here is my new script for anyone who's interested: <?php function getScriptPath() { $self = explode("/",$_SERVER['PHP_SELF']); echo $_SERVER['SERVER_NAME'].":".$_SERVER['SERVER_PORT']."/".$self[1]; } getScriptPath(); ?> Thank you everyone! You have been so helpful!