You are here: Re: path using / or ../ « All PHP « IT news, forums, messages
Re: path using / or ../

Posted by Koncept on 11/01/06 23:41

In article <1162408205.783252.128710@i42g2000cwa.googlegroups.com>,
jesbuddy07 <jesbuddy07@gmail.com> wrote:

> Can anyone point me to a right direction in terms of using / and ../
> directives to point to a file using PHP?
>
> i'm so confused when to use / or ../ or sometimes even without /.
>
> i'm writing php file in a /x/y directory, and the file i want to
> include resides is /x/z directory. in /x/y directory, I tried the
> following statements, but none of them works
>
> include("x/z");
> include("/x/z");
> include("../x/z");
>
> can any PHP guru out there please tell me when to use /, ../ or none at
> all??
>
> thanks a bunch
>

Martin clarified this, but perhaps I can explain this another way which
may help things set in...

Let's say that you have a friend call you from another city and they
want to come an visit you... When you explain the directions to them on
the phone, you would likely provide them directions from where they
reside to you right?

Next, let's say that your friend comes over and wants to know where the
bedroom is because it was a long drive and they feel exhausted. The
bedroom is located up the stairs and to the right, so you provide your
friend with these directions. You could always provide your friend with
directions all the way to your place from theirs and then give
directions to the bedroom, but that kind of behaviour may just cost you
a friendship in the end. :)

This explanation, in terms of path structure is known as an "absolute
path" vs "relative path". An absolute path is a path from point *a* to
*b* in the longest terms possible, while a relative path is relative to
a current position.

So... Relative to where you are currently reading this post, your
kitchen my be up two flights of stairs.

.../../kitchen ( another way to write this is ./../../kitchen )

but if you have already climbed one set of stairs, relative to where
you would find yourself, there is only one more set of stairs to climb

.../kitchen

you can access the document root ( for absolute paths ) using:

$_SERVER['DOCUMENT_ROOT']

and concatenate from there if you wish to use absolute path structures.

Includes are very interesting as well. Just for a demo, try this
example:

Create directory structure "./dir_one/dir_two";
--------------------------------------------------
Put this file (include.php)inside *dir_two*
<?php
// include.php
echo __FILE__, "<br />\n";
echo $_SERVER['PHP_SELF'], "<br />\n";
?>
--------------------------------------------------
Put this file inside the same directory that *contains* dir_one
<?php
// page_two.php
include_once('dir_one/dir_two/include.php');
?>

--
Koncept <<
"The snake that cannot shed its skin perishes. So do the spirits who are
prevented from changing their opinions; they cease to be a spirit." -Nietzsche

 

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

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