-1

I am uploading a navigation bar called nav.html and I would like to use PHP 7 to include this file at the top of all my pages.

This code: <?php include '/home/u783318484/public_html/nav.html';?> returns the error message,

Warning: include(/home/u783318484/public_html/nav.html): failed to open stream: No such file or directory in /home/u783318484/public_html/apply.php on line 24

Warning: include(): Failed opening '/home/u783318484/public_html/nav.html' for inclusion (include_path='.:/opt/php-7.0/pear') in /home/u783318484/public_html/apply.php on line 24

It works fine on my PC with Apache, but when I upload it to my website (hosted by Hostinger) it does this. The nav.html is in the same folder as the other pages.

osyra42
  • 558
  • 1
  • 6
  • 20
  • 1
    Are you sure you are uploading the `nav.html` file to your site? Are you using FTP to upload everything? Could you attach a screenshot of your `public_html` folder? – Chris May 07 '16 at 07:39
  • uh, I found the problem, it was a "is it plugged in?" type of things. – osyra42 May 07 '16 at 07:53
  • Possible duplicate of [Failed to open stream : No such file or directory](http://stackoverflow.com/questions/36577020/failed-to-open-stream-no-such-file-or-directory) – Vic Seedoubleyew May 15 '16 at 21:25

3 Answers3

0

Check your path and try with this

<?php include(dirname(__FILE__).'/nav.html');?>
Drone
  • 1,114
  • 1
  • 12
  • 31
  • I switched the code but it looks like it still the same error message. `Warning: include(/home/u783318484/public_html/nav.html): failed to open stream: No such file or directory in /home/u783318484/public_html/apply.php on line 24` `Warning: include(): Failed opening '/home/u783318484/public_html/nav.html' for inclusion (include_path='.:/opt/php-7.0/pear') in /home/u783318484/public_html/apply.php on line 24` – osyra42 May 07 '16 at 07:24
  • Try to give permission as 777 to the file – Drone May 07 '16 at 07:25
  • I'm very new to php so how would you do that? – osyra42 May 07 '16 at 07:26
  • which OS you are using ? – Drone May 07 '16 at 07:27
  • All of this has been made into a troubleshooting checklist already : http://stackoverflow.com/questions/36577020/failed-to-open-stream-no-such-file-or-directory – Vic Seedoubleyew May 15 '16 at 21:26
0

Use this:

<?php include ('./nav.html'); ?>

Or you could use:

<?php require ('./nav.html'); ?>
Ayan
  • 2,738
  • 3
  • 35
  • 76
-1

You can't include ABSOLUTE path from your root of your file system. This is for a very easy reason: when you upload your php to your server, will your server know your path? The answer is absolutelly NO.

For this reason you have to include your files as RELATIVE paths.

Take a look here: http://www.coffeecup.com/help/articles/absolute-vs-relative-pathslinks/

Answering your question you must to this

<?php include('nav.html');?>

or if you want that this file works in every path

<?php include(dirname(__FILE__) . "/nav.html"); ?>