无法包含我的文件
我尝试包含我的文件,但由于某种原因我不能...
这是我的结构:
在 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:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正确的路径是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.
当您包含另一个 php 文件时,就像获取该文件的内容并将其放入您的初始 (
index.php
) 文件中一样。因此,当您需要inc.php
文件中的更多文件时,它将基于初始文件的路径。尝试在index.php
文件中设置基本路径,并在inc.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 theinc.php
file it's being based on the path of the initial file. Try setting a base path in yourindex.php
file and use that in yourinc.php
file. Try只需将此页面 cl_calendar.php 拖放到您的 index.php 页面,这将显示为 href 链接,然后只需复制完整的 href 路径并将其粘贴到包含中。
或者试试这个
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