PHP Include Paths and Include Files

PHP Include Paths and Files

When working with php applications, you may often use or will often find the include() statement. The include allows you to add another file into the code. It can be seen like adding new lines in the same location; except that the lines exist in a different file. When you include a file, the path of any links exist as though they are in the original file. For example, if you include a file in a folder that is up one directory, you would write the code include("foldername/file.php").

Now, if the foldername folder contained a folder called images, you would need to write the links in the file.php file like foldername/images/myimage.jpg. However, if the image files were located in the same folder as the original file, you would make links like myimage.jpg since the path to images references from the original file.

You can always use relative or absolute paths when you link to images.

Relative Path (no forward slash at the beginning) "myimage.jpg" or "images/myimage.jpg"   

Absolute Path <a href="/images/myimage.jpg"> or <a href ="/foldername/images/myimage.jpg">