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?
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
您是否尝试过相对路径?
<?php include('./main-nav.php') ?>
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.