How do I make file names point from the top directory?

Discussion in 'HTML & Website Design' started by Imozeb, Feb 20, 2010.

  1. #1
    Here is my folder layout:


    main
    --folder: pages
    ----file1.php
    ----page.php
    ----filehead.php
    ----folder: lists
    ------file2.php



    I want to include the contents of 'filehead.php' in the files 'file1.php' and 'file2.php'. I used the PHP include() command.

    In filehead there are links to other pages with the format ../page.php. The problem arises when I include 'filehead.php' in 'file2.php' because it thinks that ../page.php means something like: ../lists/page.php. How can I fix this error without making a new 'filehead.php' file especially for the lists folder? If you need anymore information just ask. :)

    Thanks!

    ~Imozeb :)
     
    Imozeb, Feb 20, 2010 IP
  2. broxen

    broxen Peon

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    first, I assume that you understand PHP pretty well.
    in your file1.php use this code to include the filehead.php
    <?php include("filehead.php"); ?>
    PHP:
    and for the file2.php use this code.
    <?php include("../filehead.php"); ?>
    PHP:
     
    broxen, Feb 21, 2010 IP
  3. Imozeb

    Imozeb Peon

    Messages:
    666
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Okay. I know how to do that, but how do I make the links in 'filehead.php' link to the file 'page.php' from both 'file1.php' and 'file2.php' because if I include the links in 'file1.php' as 'page.php' then when I include 'filehead.php' links in 'file2.php' it does not work because the links are for 'page.php' not for '../page.php'.

    Is there anyway I can fix this or is there another way I could include files in a PHP file? Please help, I've been trying everything I know!

    ~imozeb :)
     
    Last edited: Feb 21, 2010
    Imozeb, Feb 21, 2010 IP
  4. broxen

    broxen Peon

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    try to define the path on file2.php so it's point to the files on parent directory.
    <?php define('BASE_PATH',realpath('.')); ?>
    PHP:
     
    broxen, Feb 21, 2010 IP
  5. Jarod B

    Jarod B Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You know I've always used this myself, so instead I always used a database. I made a class file for this so that I dont have to query it all the time, where I could simply call a function for this and then include the directory. You should do that, other than this.. Use the simple 2 dots to escape the current directory to the one thats closer to the top directory.

    ../directory
     
    Jarod B, Feb 22, 2010 IP