Re: Finding out the local path to a file.
| From: | Michal Migurski | Date: | Tue, 24 Feb 2004 00:59:57 +0000 |
| Subject: | Re: Finding out the local path to a file. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-178624@lists.php.net to get a copy of this message | ||
>I'm wondering if there's a way for PHP fo know the local path of
>REQUEST_URI. I've used a script to list directories, in order to replace
>the looks of the traditional Indexes look (apache). By setting
>DirectoryIndex to a fixed file (/list/lister.php) that file is now
>executed whenever there's no other indexfile in the folder. But how can I
>let it know which folder to work in? Let's say that it gets
>example.com/~simon/files/ as URL. All the local variables I've seen by
>using phpinfo() point to the location of the file, not the folder I'm
>requesting.
I just this weekend finished working through that exact problem for
http://onetwentyeight.com and http://video.teczno.com.
In general, this will only work for situations where your script
(lister.php) is in a directory directly above your URI. Your example is
troublesome, because there isn't a way to precisely determine what
filesystem directory /~simon/ maps to without parsing through your Apache
config file, which I trust you don't want to do.
If your DirectoryIndex lives someplace within the path of your
REQUEST_URI, you can use that to determine where to chdir() to.
Here's how I've been doing it:
$ru = explode('/', trim($_SERVER['REQUEST_URI'], '/'));
$sn = explode('/', trim($_SERVER['SCRIPT_NAME'], '/'));
$diff = array_diff($ru, $sn);
foreach($diff as $d => $dir) $diff[$d] = rawurldecode($dir);
if($diff) chdir(join('/', $diff));
---------------------------------------------------------------------
michal migurski- contact info and pgp key:
sf/ca http://mike.teczno.com/contact.html