salmanrsi — 2012-05-09T10:47:48-04:00 — #1
How do i get relative and absolute paths with global functions and variables. I have seen in cms like wordpress and joomla, whenever we install it, it stores paths in config.php files accurately whether we have installed it in parent domain or in sub-domain.
I tried but failed to make such function that can extract correct path working for any directory that user is installing my script. Can anybody suggest that?
jeremyc — 2012-05-09T11:03:02-04:00 — #2
If you want your current directory you can use the dirname() function.
echo dirname( __FILE__ ) . '<br />';
// ouput: /home/user/www/htdocs
If you want the parent directory:
echo dirname( dirname( __FILE__ ) );
// ouput: /home/user/www
Is this what your are looking for?
salmanrsi — 2012-05-12T00:32:39-04:00 — #3
Its fine for internal script usage to include files.
What about path that generates in URL i.e : http://localhost/mydir/mydir2/abc/myproject/ OR http://abc.mydomain.com/mydir/abc/
I dont know how wordpress and other cms gets this exactly correct. How can I have such url as I am gonna need it when I will create installer for my script.
jeremyc — 2012-05-14T09:17:18-04:00 — #4
You can use the $SERVER array, specifically the $SERVER['SERVER_NAME'] and the $SERVER['PHPSELF'] array keys. If you do a var_dump() on the $_server array you will find a ton of useful information.
I'm sorry I didn't answer sooner, it was a very long weekend. I didn't even get a chance to turn the computer on.