HTML 中不同文件夹中的文件路径


files path in different folders in html

我有以下包含文件的文件夹结构:

index.php
includes/header.php
includes/conn.php
contents/ad_list.php
contents/ad_posting.php

在我的index.php我有以下内容包括

include("includes/header.php");没关系

但在contents/ad_list.php上述包含给出以下错误:

Warning: include(includes/header.php) [function.include]: failed to open stream: No such file or directory in C:'XAMPP'xampp'htdocs'NAYAAD'contents'ad_list.php on line 4

我无法解决这个问题。

问候:

你需要上升一个级别:

include("../includes/header.php");

在这种情况下,include("../includes/header.php");解决问题,但是,最好的方法是应用程序的已知根并将其用作包含的基础。

您需要在php.ini中设置相对于应用程序根文件夹的include_path,或者尝试使用$_SERVER['DOCUMENT_ROOT'];

尝试在包含内容中包含 dirname。

<?php
include dirname(__FILE__)."/../contents/ad_list.php";
?>

dirname(_FILE)可以使其更具便携性,并且根据其运行位置,您可以复制它并根据需要添加点。

尝试在地址前面加上"."

include("./contents/ad_list.php");