• 0

Include file path?


Question

What is wrong in this code?

<?php
include "/pages/footer.html";
?>

For some reason when I try to include that (i even tried without the beginning front slash (or whatever you call it) it gave me this warning.

[b]Warning[/b]: include(/pages/footer.html) [[url="http://lacydic.com/function.include"]function.include[/url]]: failed to open stream: No such file or directory in [b]/home/lacydicp/public_html/footer.php[/b] on line [b]2[/b]

[b]Warning[/b]: include() [[url="http://lacydic.com/function.include"]function.include[/url]]: Failed opening '/pages/footer.html' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in [b]/home/lacydicp/public_html/footer.php[/b] on line [b]2[/b]

Also I am definitely correct that the file exists.

Link to comment
Share on other sites

8 answers to this question

Recommended Posts

  • 0

Is footer.html actually under /pages/ or your main directory (public_html)? I'm guessing it's /pages/, correct? Also, footer.html actually exists, correct?

Your second error is displaying because it's looking for footer.html under public_html and as it doesn't exist, you're receiving "No such file or directory" aka 404.

Link to comment
Share on other sites

  • 0

Is footer.html actually under /pages/ or your main directory (public_html)? I'm guessing it's /pages/, correct? Also, footer.html actually exists, correct?

Your second error is displaying because it's looking for footer.html under public_html and as it doesn't exist, you're receiving "No such file or directory" aka 404.

Why is it looking for it under public_html when I included /pages/?

Link to comment
Share on other sites

  • 0

Why is it looking for it under public_html when I included /pages/?

It wasn't looking under public_html, if it had been you would not have gotten the error. It was looking under the root directory of your web server, because you started with a slash. Trouble is, the root directory of your server is not the same as the root directory of your website. That is why my code fixed it. It now looks for it under "server root + path to your website root + path you specified".

Link to comment
Share on other sites

  • 0

It wasn't looking under public_html, if it had been you would not have gotten the error. It was looking under the root directory of your web server, because you started with a slash. Trouble is, the root directory of your server is not the same as the root directory of your website. That is why my code fixed it. It now looks for it under "server root + path to your website root + path you specified".

This is correct.. depending how your server is setup, it uses your server root path, that is what $_SERVER['DOCUMENT_ROOT'] does.

more info on $_SERVER can be found here

Link to comment
Share on other sites

  • 0

It wasn't looking under public_html, if it had been you would not have gotten the error. It was looking under the root directory of your web server, because you started with a slash. Trouble is, the root directory of your server is not the same as the root directory of your website. That is why my code fixed it. It now looks for it under "server root + path to your website root + path you specified".

couldn't he also have just added a . in front of the /?

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.