1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

include function doesn't work in other directories

Discussion in 'PHP' started by saturnstroll, Feb 19, 2008.

  1. #1
    Hello, I successfully used the include function on http://mrconcreteblockhouse.com/index.php which has 2 include files:

    <?php include("top.php"); ?>
    Code (markup):
    and
    <?php include("bottom.php"); ?>
    Code (markup):
    The index works just fine.

    However when I try to put the same code in http://mrconcreteblockhouse.com/f/found ... b.html.php it doesn't work.
    I then tried placing copies of top.php and bottom.php in the same /f/ directory, but still doesn't show the top or bottom.

    Then I tried defining the path to the directory:

    <?php define('PATH', '/www/mrconcreteblockhouse/httpdocs/'); ?>
    
    Code (markup):
    <?php include(PATH . "top.php"); ?>
    
    Code (markup):
    Still doesn't work.
    Any ideas?
     
    saturnstroll, Feb 19, 2008 IP
  2. fairuz.ismail

    fairuz.ismail Peon

    Messages:
    232
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #2
    make sure that the path is correct and the file is in PHP format..

    if your top.php is in root and you want to include it from a file inside a different folder, use include "../top.php"; instead.
     
    fairuz.ismail, Feb 19, 2008 IP
  3. Colbyt

    Colbyt Notable Member

    Messages:
    3,224
    Likes Received:
    185
    Best Answers:
    0
    Trophy Points:
    210
    #3
    What is the html part of that quote?

    Fairuz gave you good adive about the path.
     
    Colbyt, Feb 19, 2008 IP
  4. Cri2T

    Cri2T Peon

    Messages:
    104
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yes, I would just use "../" instead of the whole PATH . "top.php" etc.
     
    Cri2T, Feb 19, 2008 IP
  5. saturnstroll

    saturnstroll Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Yes, I'm also looking for the html equivelant/solution.
    So I tried the "../" which looks like this on /f/foundation-hub.html/
    <?php include ("../top.php"); ?>
    Code (markup):
    No go. Maybe I didn't type it correctly?
     
    saturnstroll, Feb 20, 2008 IP
  6. fairuz.ismail

    fairuz.ismail Peon

    Messages:
    232
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #6
    can you give a screen shot of your directory tree? it's different depends how you arrange your file in the directory...
     
    fairuz.ismail, Feb 21, 2008 IP
  7. Sergey Ten

    Sergey Ten Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    saturnstroll,

    Just try to rename the foundation-hub.html to foundation-hub.php
     
    Sergey Ten, Feb 21, 2008 IP
  8. fairuz.ismail

    fairuz.ismail Peon

    Messages:
    232
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #8
    yeah, i already said this to him.. make sure the path and the file format are good.
     
    fairuz.ismail, Feb 21, 2008 IP
  9. false

    false Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Or you can simply add
    AddType application/x-httpd-php .php .php5 .html
    in .htaccess file
     
    false, Feb 21, 2008 IP
  10. saturnstroll

    saturnstroll Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    That did the trick.
    Once I renamed the foundation-hub.html to foundation-hub.php, everything works with copies of top.php and bottom.php in said subdirectory.
    Thanks to all for your input.
    Problem solved. =)
     
    saturnstroll, Feb 27, 2008 IP