Absolute path relative to the site root directory

Source: Internet
Author: User

 

If you have the following file in the root directory

There are 3 folders under the HTML (root directory) images message styles

Html
--images
--a.jpg
--message
--liuyan.php
--styles
--students.css
--header.php
--footer.php
--index.php


Liuyan.php has the following code
Include (".. /header.php ");


Header.php has the following code

If I write

Then in the liuyan.php code will be in their own directory (message directory) to find images directory, and then find A.jpg. This is certainly not found, so the picture can not be found, the same, CSS file or URL to point to all wrong
Up.

If I write

Then you will go to the root directory of the images, you can find, no matter what level of directory you are, where the reference, so you can find.

Of course, if you have a header.php or footer.php in each directory, this can also solve the problem, but the complexity of the problem is the increase in order of magnitude.

At the same time, the written header.php must be written in the context of the root directory, that is, the latter. The meaning of include is to copy the code of the page you include into this PHP. Imagine if there is a src= ' images/' in the header. Code fragment, which is then used to refer to the code's sibling directory to find the images folder, which is not found and is wrong. And if there are some absolute path (relative to the root site of the absolute path) will not be asked, include or are going to the root directory under the images directory to find. That would be fine. You don't have to write headers repeatedly for each folder.

Oh, some of their own experience recorded a little. I also hope to be a bit of use to everyone. Path and coding can all be difficult in web programming. Oh ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.