You are here: Re: [PHP] [NEWBIE] Confused about usage of $_SERVER['DOCUMENT_ROOT'] « PHP « IT news, forums, messages
Re: [PHP] [NEWBIE] Confused about usage of $_SERVER['DOCUMENT_ROOT']

Posted by Andre Dubuc on 02/20/05 19:52

On Sunday 20 February 2005 12:15 pm, Dave wrote:
> PHP General,
>
> The Situation:
> I would like to be able to specify locations of scripts and files
> relative to the "root" directory from which my web site is served. I
> thought this was what $_SERVER['DOCUMENT_ROOT'] was for.
>
> The Problem:
> When I use $_SERVER['DOCUMENT_ROOT'], it creates a path starting
> from somewhere deep down in the server's file structure, below where I
> even have authorized access. So if I specify a file like so:
> $imageFile = $_SERVER['DOCUMENT_ROOT'] . "/images/image.jpg";
> ... PHP gets lost and doesn't locate it.
> What I am looking for is a variable which will specify the base
> directory that my web site is rooted in. In other words, starting from
> the same directory that my index.html file is in.
>
> The Question:
> How do I specify the directory that my web site is situated in, the
> same directory where my main index.html file is? Is there a different
> variable I should be using, or perhaps some configuration of
> $_SERVER['DOCUMENT_ROOT'] that needs to be applied?
>
> What I've Tried So Far:
> First I went to the on line PHP manual, which is where I found out
> about $_SERVER['DOCUMENT_ROOT'] in the first place. Of all the server
> variables available, 'DOCUMENT_ROOT' seems to describe what I'm looking
> for, but doesn't behave how I would expect.
> A Google search was equally ineffective in educating me in what
> basic concept I am missing.
>
> Any advice would be much appreciated.
>
> --
> Dave Gutteridge
> dave@tokyocomedy.com


Hi Dave,

Perhaps what you should do to set $imageFile = "/images/image.jpg"
since I would assume, whatever your Document_Root is, 'images' is a
sub-directory to it.

I.e.: if your servable document directory is something like
"/vhome/tokyocomedy/all_your_files_are_here"
then
"/vhome/tokyocomedy/all_your_files_are_here/images/image.jpg" is where your
image.jpg file is.

Also, check using <?php phpinfo(); ?> where the $_SERVER['DOCUMENT_ROOT'] is
(under 'PHP Variables' section) and note where tempfiles are uploaded to as
well, if you're uploading.

HTh,
Andre

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация