PHP包含文件。显示未找到错误文件 [英] PHP include file. Showing error file not found
问题描述
我使用的是include函数,它给出了错误。那是找不到的文件。
在根目录中我有 - index.php和config.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 包括 config.php 并有一些其他数据。
index.php includes config.php and has some other data.
config.php 包含数据库详细信息并包含function / function.php
config.php has database details and includes function/function.php
有一个文件夹用户,它在 calculate.php 中有一个文件 calculate.php
我已经包含了AJAX功能并在AJAX调用中加载一个文件。文件 cal2.php ,位于用户文件夹中。
现在, cal2.php 具有 config.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:
包括../ config.php;
include "../config.php";
当 cal2.php 从 calculate.php加载
function / function.php 文件未加载。它显示找不到 function / function.php的文件
function/function.php file is not loaded. It shows file not found for function/function.php
因此,文件结构为:
- root
- /index.php
- /config.php
- /user/calculate.php
- /user/cal2.php
- /function/function.php
- root
- /index.php
- /config.php
- /user/calculate.php
- /user/cal2.php
- /function/function.php
如何继续,没有function.php包含cal2.php的错误
How to proceed and not have function.php include error for cal2.php
推荐答案
您应该更改config.php以使用functions.php的绝对路径。如果你有PHP 5.3或更高版本,那就这样做:
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');
如果您仍在使用PHP 5.2(或者,上帝禁止,之前的某些内容),您可以这样做这样:
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');
__FILE__魔术常量始终包含当前PHP文件名的值,因此 dirname(__ FILE __)
call将为您提供当前脚本的完整文件系统路径。
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.
这篇关于PHP包含文件。显示未找到错误文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!