Page 1 of 1

getting the url or even just a relative path

Posted: Wed Jul 11, 2007 8:42 am
by mlecho
hi all...i have some xml that i need to utilize to give relative paths to where that xml file is...so, if the xml is in

thisFolder>xmlFiles>filename.xml

i need php to echo "thisFolder/xmlFiles/"

i have played with getcwd()

Code: Select all

<?php $p=getcwd(); echo($p."/");?>
but on the server, it gives more info than i want (ie, the root, and all before "thisFolder" ie.../home/virtual/site191/fst/var/www/html/website.com/projects/thisFolder/xmlFiles/)....any ideas?

edit** i need to be clear...i just want the path, minus the file name.....

Posted: Wed Jul 11, 2007 9:01 am
by mlecho
just had to think about it....

Code: Select all

<?php $p=getcwd();
$yy=$_SERVER['SCRIPT_FILENAME'];
$cut=$_SERVER['SCRIPT_NAME'];
$it=strlen(basename($yy));
$x=substr($cut,0,strlen($cut)-$it);
echo ($x);
?>

Posted: Wed Jul 11, 2007 9:15 am
by Zoxive

Code: Select all

function path($beg){ // beg is what dir you want to start at
     $path = pathinfo(strstr($_SERVER['SCRIPT_FILENAME'],$beg));
     return $path['dirname'];
  }

Code: Select all

print path('/thisFolder'); // would output /thisFolder/xmlFiles