Posted By

arthipesa on 01/30/10


Tagged

document root


Versions (?)

Resolving Current Document Root


 / Published in: PHP
 

URL: http://code.arthipesa.com/

  1. function resolveDocumentRoot() {
  2. $current_script = dirname($_SERVER['SCRIPT_NAME']);
  3. $current_path = dirname($_SERVER['SCRIPT_FILENAME']);
  4.  
  5. /* work out how many folders we are away from document_root
  6.   by working out how many folders deep we are from the url.
  7.   this isn't fool proof */
  8. $adjust = explode("/", $current_script);
  9. $adjust = count($adjust)-1;
  10.  
  11. /* move up the path with ../ */
  12. $traverse = str_repeat("../", $adjust);
  13. $adjusted_path = sprintf("%s/%s", $current_path, $traverse);
  14.  
  15. /* real path expands the ../'s to the correct folder names */
  16. return realpath($adjusted_path);
  17. }

Report this snippet  

You need to login to post a comment.