Reputation: 2019
I am working on a school project. My index works but when I click on 'Lab 1 Q1' located at labs/1/1.html it takes me to the page but my <?php include('/main-nav.php') ?>
is not working. I also tried <?php include($_SERVER['DOCUMENT_ROOT']."/mobile-nav.php") ?>
which did not work and I believe this is because I am currently using wamp so the 'root', I believe, is C:\wamp and inside there I have www/school/index.php.
How can I have a working file path not hard coded in?
Upvotes: 0
Views: 157
Reputation: 78
For include path, have a look in include_path directive in your php.ini
you can also try a
<?php phpinfo() ?>
and search the "include_path" directive
"/" have no sense in a Windows OS.
Upvotes: 0
Reputation: 28911
The include
method is using server-side paths, so /main-nav.php
is looking for the file in the root folder of your hard drive.
One option is to use a relative path:
include('../../main-nav.php'); // Go up two levels
Upvotes: 3
Reputation: 2224
Did you try with a relative path?
<?php include('./main-nav.php') ?>
Upvotes: 1