1

I'm trying to use php include to include articles on a web page... My file structure looks like this:

  1. /Articles
    • /articles
      • App_Template.html
    • /tags
      • /new
        • index.html
    • /including
      • File.html

In App_Template.html I have the piece of code:

<?php include("../including/File.html"); ?>

Which works fine and displays the correct article when you access App_Template.html, However the code:

<?php include(".../including/File.html"); ?>

Within index.html in the new folder doesn't work and throws these errors:

Warning: include(.../including/File.html) [function.include]: failed to 
open stream: No such file or directory in 
/home/a1696768/public_html/articles/tags/new/index.html on line 79


Warning: include() [function.include]: Failed opening
 '.../including/File.html' for inclusion 
(include_path='.:/usr/lib/php:/usr/local/lib/php') 
in /home/a1696768/public_html/articles/tags/new/index.html on line 79

I've tried searching around to find a reason for this but cannot however find any reason as to why this isn't working here but is in App_Template.html, the only thing I can possibly imagine is it's something to do with the fact the second case is an index.html?

1 Answer 1

1

You can't use three dots ... in paths, it's either .. for one level up or . for the current level. If you want to go 2 folders/levels up, use ../../yourfile.

Sign up to request clarification or add additional context in comments.

6 Comments

Ok that works when I access www.my-site.co.uk/new/index.html... However when I just go to www.my-site.co.uk/articles/new/ It still doesn't work :/ Is there any easy to get it working from both?
Otherwise I'm gonna have to go and change all my links to certain tags to /tag_name/index.html ;)
Includes work relative to where the script is. If you are in yoursite.co.uk/articles/new/index.html and go up 1 directory, you end up in yoursite.co.uk/articles/. If you are in yoursite.co.uk/new/index.html and go up 1 directory, you end up in yoursite.co.uk/ which probably does not have the file you want (or the other way round). I hope you get the idea. One solution to this would be to use the full path /home/a1696768/public_html/articles/tags/new/index.html in every include you use, that saves you from guessing how many directories you have to go up (.. or ../../ or even more).
Hmmm for some reason this still doesn't work unless i visit the respective index.html! Is this because it takes a certain time for the folder's automatic page to update like with uploading a favicon?
I can only guess what you are trying here: Including only works from your index.html where you do the includes, your articles don't know that they are included from somewhere else. If you are looking for nice urls like yoursite.co.uk/article/example-article, search for "mod rewrite", there are lots of tutorials and questions on the web and Stackexchange also.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.