无法包含我的文件

发布于 2025-01-07 01:01:30 字数 755 浏览 0 评论 0原文

我尝试包含我的文件,但由于某种原因我不能...

这是我的结构:
在此处输入图像描述

index.php 上,有一个 include_once('includes /php/inc.php');inc.php 包含这些行:

// Required classes 
require_once '../classes/cl_calendar.php';

我认为完全合法,但由于某种原因,我得到的只是这个错误:

Warning: require_once(../classes/cl_calendar.php): failed to open stream: No such file or directory in /customers/xxx/xxx/httpd.www/new/extra/php/inc.php on line 14 Fatal error: require_once(): Failed opening required '../classes/cl_calendar.php' (include_path='.:/usr/share/php') in /customers/xxx/xxx/httpd.www/new/extra/php/inc.php on line 14

是什么导致显示此错误以及如何摆脱它?

I try to include my files, but for some reason I can't...

Here is my structure:
enter image description here

On index.php, there is a include_once('includes/php/inc.php');. The inc.php contains these lines:

// Required classes 
require_once '../classes/cl_calendar.php';

Perfect legitimate I think, but for some reason all I get is this error:

Warning: require_once(../classes/cl_calendar.php): failed to open stream: No such file or directory in /customers/xxx/xxx/httpd.www/new/extra/php/inc.php on line 14 Fatal error: require_once(): Failed opening required '../classes/cl_calendar.php' (include_path='.:/usr/share/php') in /customers/xxx/xxx/httpd.www/new/extra/php/inc.php on line 14

What makes this error to be displayed and how do I get rid of it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

仙女 2025-01-14 01:01:30

正确的路径是includes/classes/file.php。为什么..?这将使您比根更上一层。

原因是,即使两个包含文件的相对关系可能不同,但您是从索引文件中包含它,因此路径必须相对于索引文件。

The correct path is includes/classes/file.php. Why the ..? This would lead you one level over the root.

The reason for that is that even though the relative relation of the two included files may be a different one, you're including it from the index file and therefore the path has to be relative to the index file.

裂开嘴轻声笑有多痛 2025-01-14 01:01:30

当您包含另一个 php 文件时,就像获取该文件的内容并将其放入您的初始 (index.php) 文件中一样。因此,当您需要 inc.php 文件中的更多文件时,它将基于初始文件的路径。尝试在 index.php 文件中设置基本路径,并在 inc.php 文件中使用该路径。尝试

// index.php
$base = "/var/www/htdocs/";  
// or something like dirname(__FILE__) if it may change
include_once($base.'includes/php/inc.php');

// inc.php
require_once($base.'classes/cl_calendar.php');

When you include a php file from another, it's just like taking the contents of that file and placing it in your initial (index.php) file. So, when you to require more files from the inc.php file it's being based on the path of the initial file. Try setting a base path in your index.php file and use that in your inc.php file. Try

// index.php
$base = "/var/www/htdocs/";  
// or something like dirname(__FILE__) if it may change
include_once($base.'includes/php/inc.php');

// inc.php
require_once($base.'classes/cl_calendar.php');
雨的味道风的声音 2025-01-14 01:01:30

只需将此页面 cl_calendar.php 拖放到您的 index.php 页面,这将显示为 href 链接,然后只需复制完整的 href 路径并将其粘贴到包含中。

或者试试这个

require_once(/../classes/cl_calendar.php);

Just Drag and drop this page cl_calendar.php to your index.php page, and and this will showing as href link then just copy full href path and paste it as it is in include.

or try this one

require_once(/../classes/cl_calendar.php);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文