#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2010
    Posts
    24
    Rep Power
    0

    SSI across different folder levels?


    Hi all,

    I've finally discovered SSI and think it's the greatest thing since sliced bread. The problem I'm having is reusing the include files on a different folder level.

    For example, my include file test.incl has this content:
    <img src="images/test.jpg">

    the index.shtml document has this line:
    <!--#include file="includes/test.incl" -->

    That works for all documents on the same folder level, but as soon as I go a level deeper, the link breaks.

    It doesn't seem to matter if I change the path in the lower level document to
    <!--#include file="/includes/test.incl" -->
    or
    <!--#include file="../includes/test.incl" -->

    How can this be fixed?

    Thanks,
    Stefan
  2. #2
  3. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,127
    Rep Power
    4304
    Use a web-root relative URL (it's the leading slash that makes the difference):
    Code:
    <img src="/images/test.jpg">
    I recommend PHP includes as a better alternative to SSI.
    Last edited by Kravvitz; August 25th, 2013 at 09:54 PM.
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2010
    Posts
    24
    Rep Power
    0
    Originally Posted by Kravvitz
    Use a web-root relative URL (it's the leading slash that makes the difference):
    Code:
    <img src="/images/test.jpg">
    I recommend PHP includes as a better alternative to SSI.
    I tried with the root relative level and actually put the exact contents of the include file in the file itself to test. When I paste the contents, it works, but when I use include, it does not.

    These are my files in a nutshell:

    toplevel.shtml contains <!--#include file="/dev/includes/test.incl" -->

    level2.shtml contains the same <!--#include file="/dev/includes/test.incl" -->

    /dev/includes/test.incl contains <img src="/dev/images/backdrop.jpg" alt="--">

    /dev/images/backdrop.jpg obviously is the image.

    In this scenario, both pages will return the processing error.

    I also tried replacing the code with php according to the tutorial you linked to and renamed the files with .php. Otherwise the structure is the same as above. Processing did not return an error, but blank pages in both cases.

    Any ideas?

    Thanks,
    Stefan
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2009
    Location
    Nebraska, USA
    Posts
    876
    Rep Power
    275
    What happens if you add the width="" and height="" properties in your IMG tag and put the image's height/width in there?
  8. #5
  9. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,127
    Rep Power
    4304
    Sorry, I should have stated more clearly that I meant you should change the paths for the images but not the includes. If you want to use web-root relative paths for your includes, you'll need to use "virtual" instead of "file".
    Code:
    <!--#include virtual="/dev/includes/test.incl" -->
    I also tried replacing the code with php according to the tutorial you linked to and renamed the files with .php. Otherwise the structure is the same as above. Processing did not return an error, but blank pages in both cases.
    That's very odd. What happens when you create (and upload) a file called "phpinfo.php" with the following snippet as the contents? Do you still get a blank page?
    Code:
    <?php phpinfo(); ?>
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2010
    Posts
    24
    Rep Power
    0
    Originally Posted by Kravvitz
    Sorry, I should have stated more clearly that I meant you should change the paths for the images but not the includes. If you want to use web-root relative paths for your includes, you'll need to use "virtual" instead of "file".
    Code:
    <!--#include virtual="/dev/includes/test.incl" -->
    Yep, it works now! Very nice. So what exactly is the difference between file ad virtual? Or rather why would you want to use file instead of virtual? Seems to be a redundant command.

    Originally Posted by Kravvitz
    That's very odd. What happens when you create (and upload) a file called "phpinfo.php" with the following snippet as the contents? Do you still get a blank page?
    Code:
    <?php phpinfo(); ?>
    I get a large technical readout which informs me (among other things) that php 5.4.19 is running.

    Thanks very much!
    Stefan
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2010
    Posts
    24
    Rep Power
    0
    Originally Posted by DonR
    What happens if you add the width="" and height="" properties in your IMG tag and put the image's height/width in there?
    That's not the problem (see above). I *think* the dimensions' purpose is to let the browser draw the image faster since it knows how large the image is. Of course, the dimensions need to be correct, otherwise the browser is forced to scale the image which will take even longer!

    Stefan
  14. #8
  15. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,127
    Rep Power
    4304
    Originally Posted by stefangs
    Yep, it works now! Very nice. So what exactly is the difference between file ad virtual? Or rather why would you want to use file instead of virtual? Seems to be a redundant command.
    You're welcome.

    I don't use SSI, so I only know what the documentation says.

    Originally Posted by stefangs
    I get a large technical readout which informs me (among other things) that php 5.4.19 is running.
    Yeah, that's what you're supposed to see. I would probably need to see a live example page to diagnose why the include wasn't working. Are you interested in pursuing that or would you like to stick with SSI?
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2010
    Posts
    24
    Rep Power
    0
    Originally Posted by Kravvitz
    Are you interested in pursuing that or would you like to stick with SSI?
    Since I don't know any php worth mentioning, I think I'll stick to SSI which is more accessible to me and actually quite similar to an include tool I used for offline editing.

    Thanks again and congrats on your 20000th post - wow!

    Stefan

IMN logo majestic logo threadwatch logo seochat tools logo