PHP 包含文件。显示错误文件未找到
我正在使用 include 函数,但它给出了错误。那就是找不到文件。 在根目录中,我有 - index.php 和 config.php
index.php 包括 config.php 并具有一些其他数据。
config.php 包含数据库详细信息,并包含 function/function.php
有一个文件夹 user,它有一个文件 calculate.php 在 calculate.php 中,我包含了 AJAX 功能,并在 AJAX 调用时加载了一个文件。文件是cal2.php,它位于user文件夹中。 现在,cal2.php 具有 config.php 的包含函数,例如:
包含“../config.php”;
当从 calculate.php 加载此 cal2.php 时,
不会加载 function/function.php 文件。它显示找不到 function/function.php 文件
,因此,文件结构为:
- root
- /index.php
- /config.php
- /user/calculate.php
- /user/cal2.php
- /function/function。 php
如何继续而不让 function.php 包含 cal2.php 的错误
I am using include function and it is giving errors. That is file not found.
In the root directory I have - index.php and config.php
index.php includes config.php and has some other data.
config.php has database details and includes function/function.php
There is a folder user and it has a file calculate.php
in calculate.php I have included AJAX functionality and a file is loaded in it on AJAX call. File is cal2.php and it is located in user folder.
Now this, cal2.php has a include function for config.php like:
include "../config.php";
When this cal2.php is loaded from calculate.php
function/function.php file is not loaded. It shows file not found for function/function.php
So, file structure is:
- root
- /index.php
- /config.php
- /user/calculate.php
- /user/cal2.php
- /function/function.php
How to proceed and not have function.php include error for cal2.php
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该更改 config.php 以使用functions.php 的绝对路径。如果您有 PHP 5.3 或更高版本,请这样做:
如果您仍在使用 PHP 5.2(或者,上帝保佑,更早的版本),您可以这样做:
__FILE__ 魔术常量始终包含当前 PHP 文件的值name,因此
dirname(__FILE__)
调用将为您提供当前脚本的完整文件系统路径。You should change config.php to use an absolute path to functions.php. If you have PHP 5.3 or greater, do it like this:
If you are still using PHP 5.2 (or, god forbid, something earlier), you can do it this way:
The __FILE__ magic constant always contains the value of the current PHP file name, so the
dirname(__FILE__)
call will give you the full filesystem path of the current script.使用绝对路径包含文件:
Use absolute path to include file:
这里的所有问题都
需要以这样的方式包含:
但是我遇到了这个问题,我建议你在每个页面的标题中包含文件。您必须将配置包含在每个页面的标题中。
阅读本文,认为它有帮助:
全局变量的问题
All problems here
you need to include such a way:
BUT I had this problem to, and I propose you to include files in the header of each page. Config you must inckude in the header of each page.
Read this, think it helps:
problems with global variables