Justtechjobs.com Find a programming school near you






Online Campus Both


php3-list | 199903

Re: [PHP3] Does PATH_INFO require absolute urls From: Dan Delaney (Dionysos <email protected>)
Date: 03/31/99

On Thu, 1 Apr 1999, Paul Meagher wrote:
> All my images break when I replace ? with / and try to
> extract the arguments via PATH_INFO.
>
> http://www.mydomain.com/path/script.php3/arg1/arg2
>
> If I want to use PATH_INFO does this mean that I have
> to convert all of my relative URLs to absolute URLs?

No. I assume /path/script.php3 is a generic program which will be
called from other programs all over the directory structure of the
web server? In that case, what you'll need to do is get the path of
the calling program from the "REQUEST_URI" variable. You'll have to
strip off the file name at the end, with something like:

$path = substr($REQUEST_URI, 0, strrpos($REQUEST_URI, '/') );

That will give you the path in which the calling program resides,
without the ending '/'. Then you can use the $PATH_INFO variable to
get the specified file:

$filepath = $path.$PATH_INFO;

Now this is gonna limit the program to ONLY specifying files
relative to the calling program. What I do with my LastUpdated
program (www.Dionysia.org/software/lastupdated) is I allow the file
to be specified from the document_root if the extra path info begins
with an extra '/'. So let's say you have a PHP program which will
give output a specified GIF or JPEG file flipped horizontally--call
it "hflip.php". This line:

<IMG SRC="/scripts/flip.php/graphics/image.gif">

would get a file called image.gif inside the "graphics" directory IN
THE DIRECTORY of whatever file was calling the script.php3
program--that is, the file which contains this IMG tag, wherever it
is in the directory structure of the web server. But this line:

<IMG SRC="/scripts/randomimage.php3//graphics/image.gif">

would get a file called image.gif inside the "graphics" directory AT
THE DOCUMENT_ROOT of the web server. Your hflip.php program, of
course, would have to check for this extra '/' at the beginning of
$PATH_INFO in order to know whether to add the $path variable (taken
from $REQUEST_URI) to the beginning of $PATH_INFO. If the extra '/'
was there it would have to get rid of it and go from $DOCUMENT_ROOT
instead.

-- Dan
____________________________________________________________________________
 Daniel G. Delaney * Dionysos <email protected> * www.Dionysia.org/~dionysos
 PGP Public Key: http://Dionysia.org/~dionysos/pgp5.html

     "Only two things are infinite: the universe and stupidity--
      and I'm not sure about the former."
                                          --Albert Einstein

--
PHP 3 Mailing List   http://www.php.net/
To unsubscribe send an empty message to php3-unsubscribe <email protected>
To subscribe to the digest list:  php3-digest-subscribe <email protected>
For help: php3-help <email protected>  Archive:  http://www.php.net/mailsearch.php3
List administrator:  zeev-list-admin <email protected>