dprlv04662
dprlv04662
2015-11-09 10:33

如何包含主PHP文件所在文件夹之外的PHP文件?

已采纳

This is my directory:

Wamp>www>Newlinks
  CSS (folder)
  header.php
  footer.php
    Profiles (folder)
      MainPHPfile.php

Now, I want to include the header and footer files into MainPHPfile.php, but it's not working. How to set the path so that it works?

Same problem is with CSS. I want to use CSS files from CSS folder for those header and footer files. Please solve this problem. I shall be thankful to you.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

3条回答

  • dsxd62219570 dsxd62219570 6年前

    You could go a directory up with .. like this:

    <?php
    include '../header.php';
    include '../footer.php';
    

    Same with CSS.

    点赞 评论 复制链接分享
  • dongshu9458 dongshu9458 6年前

    You can use ../path/folder/to/file.ext to go to the previous path. /path/folder/to/file.ext to go to the root of your website e.g /public-html/ or /htdocs/ .

    点赞 评论 复制链接分享
  • douxianji3367 douxianji3367 6年前

    In order to go up a folder, use the ../ relative path, if you need to go down a folder, just writte the relative continuous path. example/another_folder/file.php

    点赞 评论 复制链接分享