简体   繁体   English

嵌套文件夹中的PHP_include文件

[英]PHP_include file from nested folders

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. 我的索引有效,但是当我单击位于labs / 1 / 1.html的“实验室1 Q1”时,它将带我到页面,但是我的<?php include('/main-nav.php') ?>无法正常工作。 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. 我还尝试了<?php include($_SERVER['DOCUMENT_ROOT']."/mobile-nav.php") ?> ,该方法无法正常工作,我相信这是因为我当前使用的是wamp,所以我相信'root' ,是C:\\ wamp,里面有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 . include方法使用服务器端路径,因此/main-nav.php硬盘驱动器的根文件夹中查找文件。

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 对于包含路径,请查看您的php.ini中的include_path指令

you can also try a 您也可以尝试

<?php phpinfo() ?>

and search the "include_path" directive 并搜索“ include_path”指令

"/" have no sense in a Windows OS. 在Windows操作系统中,“ /”没有意义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM