PHP 包含文件。显示错误文件未找到

发布于 2024-10-08 04:16:03 字数 938 浏览 1 评论 0原文

我正在使用 include 函数,但它给出了错误。那就是找不到文件。 在根目录中,我有 - index.php 和 config.php

index.php 包括 config.php 并具有一些其他数据。

config.php 包含数据库详细信息,并包含 function/function.php

有一个文件夹 user,它有一个文件 calculate.phpcalculate.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 技术交流群。

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

发布评论

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

评论(3

迎风吟唱 2024-10-15 04:16:03

您应该更改 config.php 以使用functions.php 的绝对路径。如果您有 PHP 5.3 或更高版本,请这样做:

include __DIR__.'/functions/functions.php';

如果您仍在使用 PHP 5.2(或者,上帝保佑,更早的版本),您可以这样做:

$dir = dirname(__FILE__);
include $dir.'/functions/functions.php';

__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:

include __DIR__.'/functions/functions.php';

If you are still using PHP 5.2 (or, god forbid, something earlier), you can do it this way:

$dir = dirname(__FILE__);
include $dir.'/functions/functions.php';

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.

高冷爸爸 2024-10-15 04:16:03

使用绝对路径包含文件:

$_SERVER['DOCUMENT_ROOT'].'/function/function.php'

Use absolute path to include file:

$_SERVER['DOCUMENT_ROOT'].'/function/function.php'
诗笺 2024-10-15 04:16:03

这里的所有问题都

/user/cal2.php
/function/function.php

需要以这样的方式包含:

include('../config.php');

但是我遇到了这个问题,我建议你在每个页面的标题中包含文件。您必须将配置包含在每个页面的标题中。

阅读本文,认为它有帮助:

全局变量的问题

All problems here

/user/cal2.php
/function/function.php

you need to include such a way:

include('../config.php');

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

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