PHP The difference between full and relative paths. The file system is also on site.
your site exists as if in two dimensions.
Real and virtual.
For all visitors - is a virtual web server. Which is characterized, among other things, the fact that it is NOT an existing file. if you write
<a href="http://site.ru/file.html" target="_blank">http://site.ru/file.html - it is not a file. This URI, the virtual address. No file called file.html on the server may not be. It's all virtual addresses, rather than files. And the browser to work with addresses.
For Developer same site - a program that runs on a completely specific real computer. With a brand-specific hard drive, directories and files. And the script, working with your data, loading other scripts, working it with real files on the physical disc.
It is in this difference and lie difficulties often faced by newcomers.
Losing files, links confused with files, refer to local files over HTTP, or inklyudyat files from the Web server root.
All in all, it is necessary to clearly understand two things:
1. Distinguish between the root of the web server, as seen by the browser, and the root file system on the disk.
2. The relative path from the absolute difference.
Let's start with the second.
It's very simple. If the path specified by the system root, it is an absolute path. It's like a postal address in real life - where you would not go, but the exact address you always find exactly the right place.
examples of absolute paths:
/var/www/site/forum/index.php
/img/frame.gif
с:\windows\command.com /var/www/site/forum/index.php
/img/frame.gif
с:\windows\command.com in Unix-based systems and web sites root is denoted by a slash - "/". It is important. This is not simply a wand and a separate ADDRESS way.
In an address
http://www.site.ru/ last slash - not for beauty! It refers to a very specific address - the beginning of the site. On the drive in Unix systems, so you can type "cd /" and you will go to the root directory.
In vindous systems file system is divided by the disks, so in the absolute address is necessary to specify the drive letter. Absolute root of the entire file system vindous not, each drive - his own. For example, C: \ E: \
therefore, even if the path to vindous begins with a slash, it is not an absolute path, and relative. Regarding the current disc. A perfect start with a letter.
If at the beginning of the root path is not specified, this path is relative, and it dostaivaetsya from the current position. In real life, this is reminiscent of the way to the liquor store - "two blocks to the left and right there the whole time." Reaching such a path only from a specific point. From the other you will enter is already in a very different place.
The simplest example of a relative path - it's just a file name.
If the file is located in the same directory to which the program works - it will find it, adding the current path to the file name.
Examples of relative paths:
file.php (halyard is in the same folder) ./file.php (halyard is in the same folder. this record is sometimes required in some Unix systems) images/picture.jpg (the file is in the kapok images, which is in the current) ../file.php (the file is in a folder that is one level above the current) ../../file.php (the file is in a folder that is located on two levels above the current) And the operating system and browser you are encountering a relative path to the absolute finish building it. but everyone - in its own way.
We now turn to the first item.
The difference of the root, as seen by a browser the web server, and the root file system on the disk.
In general, the previous explanations have all should be clear.
On the drive path to the script might be:
/var/www/site/forum/index.php At the same time, the virtual address of the script when viewed through the browser is: http://www.site.ru/forum/index.php This example is easy to see where the two measurements intersect: these two locations have a common part - /forum/index.php - and it's just causes confusion. For the browser is the full path, which only can be. It begins from the root of the site.
For the same script running on a server - it's just part of the way.
for the script path
/forum/index.php would be non-existent - in the root directory no forum! to get the full path for the fact that the site looks like
/forum/index.php , it is necessary to fasten it to the left path to the folder, which is considered kornevaoy entire web server. in our example - is
/var/www/site , this path is defined in kofiguratsii web server and that it is contained in the system variable, the PHP $_SERVER [ 'DOCUMENT_ROOT' ]
$_SERVER [ 'DOCUMENT_ROOT' ] The virtual server is - is that the user sees - on the contrary, there is no disk. There is a root site. That is, for any reference guaranteed to work, regardless of the site of a space it is called, it must be absolute.
If you have a site has, for example, two sections:
http://www.site.ru/about/info.php and
http://www.site.ru/job/vacancy.php then, if the file
info.php to link just to vacancy.php , the browser will not find it - it will look up the address http://www.site.ru/about/vacancy.php , constructing additions path from the current directory. Therefore it is necessary to write the complete path from the root of the site -
/job/vacancy.php
All this applies, of course, not only the tag
<a> and <img> and any other that uses links to other files. Links to local addresses should be written without the protocol and domain - only the path from the site root -
/job/vacancy.php . Links to other sites also must be written in full - http://www.site1.ru/job/vacancy.php . PHP provides a set of tools for working with files, directories and URL-s.
Firstly, it is the many predefined variables, which are described in the documentation and values in your script looked pmozhno using
phpinfo() : __FILE__ Constant contains the name of the current executable.
Unlike PHP_SELF it contains the file name currently ispolyayuschegosya.
very useful design seems
dirname ( __FILE__ )
dirname ( __FILE__ ) On which it is desirable to replace all files challenges that lie in the same directory as the calling script. For example: require dirname ( __FILE__ ). "/init.php" function dirname() , along with a basename() is one of the most common to work with files and directories. by phpfaq.ru

Comments
Commenting, keep in mind that the content and the tone of your messages can hurt the feelings of real people, show respect and tolerance to his interlocutors, even if you do not share their opinion, your behavior in terms of freedom of speech and anonymity offered by the Internet, is changing not only virtual, but real world. All comments are hidden from the index, spam control.