[mp2] a way to map a uri to a physical path

[mp2] a way to map a uri to a physical path

am 15.01.2009 05:11:08 von Foo JH

Hi all,

I'm trying to find the class/ method which allows me to get the physical
path base on the uri. Something similar to Server.MapPath('/index.htm')
in ASP.NET.

Any advise is appreciated. Thanks.

Re: [mp2] a way to map a uri to a physical path

am 15.01.2009 05:15:49 von Adam Prime

Foo JH wrote:
> Hi all,
>
> I'm trying to find the class/ method which allows me to get the physical
> path base on the uri. Something similar to Server.MapPath('/index.htm')
> in ASP.NET.
>
> Any advise is appreciated. Thanks.

$r->document_root . $r->uri

but that won't actually tell you if that file exists, it's just where
you'd probably expect that file to reside. Not having any idea how that
ASP.NET function works, i don't know if that really answers your
question or not.

Adam

Re: [mp2] a way to map a uri to a physical path

am 15.01.2009 05:58:02 von Foo JH

Adam Prime wrote:
>> I'm trying to find the class/ method which allows me to get the physical
>> path base on the uri. Something similar to Server.MapPath('/index.htm')
>> in ASP.NET.
>>
>> Any advise is appreciated. Thanks.
>
> $r->document_root . $r->uri
Thanks for replying. In my case it's a wee bit more complicated (forgot
to mention).

Thing is, I have alias-ed a path (eg. alias /thisuri c:/wwwroot) in the
web server, so $r->uri may not point to the right location.

Is there a generic method so that given any uri as a parameter, the
library can do the math and return the physical path?

Re: [mp2] a way to map a uri to a physical path

am 15.01.2009 06:26:04 von Adam Prime

Foo JH wrote:
> Adam Prime wrote:
>>> I'm trying to find the class/ method which allows me to get the physical
>>> path base on the uri. Something similar to Server.MapPath('/index.htm')
>>> in ASP.NET.
>>>
>>> Any advise is appreciated. Thanks.
>> $r->document_root . $r->uri
> Thanks for replying. In my case it's a wee bit more complicated (forgot
> to mention).
>
> Thing is, I have alias-ed a path (eg. alias /thisuri c:/wwwroot) in the
> web server, so $r->uri may not point to the right location.
>
> Is there a generic method so that given any uri as a parameter, the
> library can do the math and return the physical path?
>

$r->filename by the looks of things.

http://perl.apache.org/docs/2.0/api/Apache2/RequestRec.html# C_filename_

Adam

Re: [mp2] a way to map a uri to a physical path

am 15.01.2009 08:11:08 von Foo JH

Adam Prime wrote:
> Foo JH wrote:
>> Adam Prime wrote:
>>>> I'm trying to find the class/ method which allows me to get the physical
>>>> path base on the uri. Something similar to Server.MapPath('/index.htm')
>>>> in ASP.NET.
>>>>
>>>> Any advise is appreciated. Thanks.
>>> $r->document_root . $r->uri
>> Thanks for replying. In my case it's a wee bit more complicated (forgot
>> to mention).
>>
>> Thing is, I have alias-ed a path (eg. alias /thisuri c:/wwwroot) in the
>> web server, so $r->uri may not point to the right location.
>>
>> Is there a generic method so that given any uri as a parameter, the
>> library can do the math and return the physical path?
>>
>
> $r->filename by the looks of things.

I'm not sure if that's the one. From the docs (your ref link):

filename

Get/set the filename on disk corresponding to this response (the result
of the URI --> filename translation).

Sounds like this method assigns a file to the uri instead.

Re: [mp2] a way to map a uri to a physical path

am 15.01.2009 08:49:27 von torsten.foertsch

On Thu 15 Jan 2009, Foo JH wrote:
> Is there a generic method so that given any uri as a parameter, the
> library can do the math and return the physical path?

If you look for the filename for $r->uri, that means the uri of the
current request then $r->filename holds that after the map-to-storage
phase.

If you need a general method to map an arbitrary URI to a filename then
it is a subrequest:

my $subr=$r->lookup_uri($uri);
if( $subr->status == Apache2::Const::OK and
-f $subr->filename ) {
$filename=$subr->filename;
}

But keep in mind that it may result in quite unusual filenames if you
use the mod_proxy handler for example. Also, the file may not exist.
The status 404 is generated only in the response phase. Further, you
must perhaps check $subr->path_info for being empty.

Torsten

--
Need professional mod_perl support?
Just hire me: torsten.foertsch@gmx.net