Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Apr 2007
    Location
    U.S.A
    Posts
    129
    Thanks
    1
    Thanked 0 Times in 0 Posts

    php include pics + html/folder from seperate folder.

    I know how to use the php include funtion, but it only seems to work in the same folder, or from a folder to sub-folder. I was wondering if there is a way to do these things, as it would make my website a lot easier to maintain.
    Is there a way I can include pictures, or folders that include pictures? Can I include a folder of items? Can I include " html_root/home/folder/header.php" in "html_root/mypage/folder/index.php"?

    Thanks,


    Joe

  • #2
    Regular Coder
    Join Date
    Mar 2007
    Location
    Quebec
    Posts
    261
    Thanks
    6
    Thanked 7 Times in 7 Posts
    PHP Code:
    <?php
    include("/home/site_login_username/public_html/path_to_file/filename.php");
    ?>
    A real example:
    PHP Code:
    <html>
    <head>
    <title>Example Page</title>
    </head>
    <body>
    <div id="header">
      <?php
      
    include("/home/ridemtl/public_html/include/header.php");
      
    ?>
    </div>
    </body>
    </html>
    As for including folders, no, it's not possible. Or at least to my knowledge it isn't. Although I suppose you can include a file in an included file, I don't see anything that could go wrong with that.
    Last edited by fl00d; 08-22-2007 at 01:59 AM.

  • #3
    Regular Coder
    Join Date
    Apr 2006
    Posts
    231
    Thanks
    9
    Thanked 1 Time in 1 Post
    I have never tried including images, only include scripted files. I just echo the images, not include.

    Including stuff in different folders is easy, you just need to backup the script. each perdiod (.) includes 1 backup. so to include home/header.php in home/stuff/morestuff/index.php, you would use "../header.php"

    And as far as including folders, I am pretty sure you can find yourself a nice snippet (or code) that will echo the files in a folder, and then just include that snippet. (its called directory handle)

  • #4
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    That's not entirely true, Erin. To "backup" directories you use two periods per directory(../images/etc.jpg); One period points to the current directory(./etc.jpg). fl00d was right about the full paths though, those should work. Just make sure you always start it with a backslash on linux.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •