getting the url or even just a relative path

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mlecho
Forum Commoner
Posts: 53
Joined: Wed Feb 02, 2005 9:59 am

getting the url or even just a relative path

Post 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.....
mlecho
Forum Commoner
Posts: 53
Joined: Wed Feb 02, 2005 9:59 am

Post 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);
?>
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post 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
Post Reply