Just wanted to post some code.
Posted in general - January 21, 2008

As I was creating this monstrosity I already knew it was probably going to be really confusing and possibly pointless. Well, the objective was to have a PHP file find its base directory. Even when its included in another file in another directory. Using a relative URL's to its base... and I couldn't find other solutions for that. So this is what I have... am I crazy or is there a easier way to come up with this same solution? I don't know.

<?php $rel_dir = "../"; // Symbolic Path to base directory
 
$sys_dir = str_replace("\\","/",realpath(str_replace("\\","/",dirname(__FILE__))."/".$rel_dir)); // System path to base directory
$url_dir = "http://{$_SERVER['HTTP_HOST']}".str_replace(str_replace("\\","/",realpath($_SERVER['DOCUMENT_ROOT'])),"",$sys_dir); // URL to base directory
 
?>

Posted By YouDon'tMeanMuch at 8:59 pm


Comment on this post

  Name:
  E-Mail:
  Website:
  Comment: