php - Linux 灯需要文件

标签 php linux include require

不久前我开始使用Linux作为操作系统主体。但我在包含文件时遇到问题。 当我尝试包含一个文件,而该文件又包含第三个文件时,我最终收到错误:“无法打开流:/var/www/html/... 中没有此类文件或目录

例如我的文件是这样分发的:

enter image description here

这3个文件的代码是:

primero.php

require_once '../B/c/segundo.php';

segundo.php

require_once '../d/tercero.php';

tercero.php

echo 'success';

错误: Error

有人可以向我解释一下发生了什么吗?这在 Windows 中有效。事实是我会避免使用“dirname(FILE)”

PD:抱歉,我无法发布图片

最佳答案

使用相对路径,有时会很痛苦。因此,我开始做的是创建一个 settings.inc.php 文件,我保留重要的路径。例如:

试试这个: 设置.inc.php

<?php
define("ROOT_PATH" , dirname(__FILE__) . "/");
define("CLASS_PATH", ROOT_PATH . "class/");
?>

然后,我需要 header.php 中的设置文件(这样我就可以在每个页面上都有它)

require_once("settings.inc.php");

我这样使用它

require_once(ROOT_PATH . 'B/c/segundo.php');

还有

require_once(ROOT_PATH . 'd/tercero.php');

关于php - Linux 灯需要文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28801051/

相关文章:

javascript - 将 javascript 代码应用于两个不同的 php 页面

php - Codeigniter REST API 提供未知方法?

php - Symfony2表单数输入超20亿

linux - 格式化grep命令有更好的显示

php - PDO Informix ODBC 驱动程序可与 PHP CLI 一起使用,但不能在浏览器中使用

include - 获取编译器:Error-Row when the compile error occurs in an include file

javascript - 使用 AJAX 发布到同一页面时无法收到正确的响应

linux - 开关盒 : Confusing error in "Syntax error: word unexpected (expecting "in")"

php - 如何处理 PHP 中包含的链接?

android - 为 android 编译 SDL 时找不到 ifaddrs.h header