我很确定我写错了目录。
这是我在 Postman 上遇到的错误:
警告:require_once(./includes/functions.php):无法打开流:第3行的/var/www/html/includes/database.php 中没有这样的文件或目录致命错误:require_once():需要打开失败' ./includes/functions.php' (include_path='.:/usr/local/lib/php') 在/var/www/html/includes/database.php第3行
我的文件结构:
PHP
_api/
__index.php
_includes/
__database.php
__functions.php
我的 index.php 文件:
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
require_once('../includes/database.php');
$db = new operations();
$result=$db->view_record();
?>
database.php 文件中的 require_once:
<?php
session_start();
require_once('./includes/functions.php');
?>
在functions.php中:
<?php require_once('./includes/database.php');?>
如果有人可以帮助我找到我的代码中缺少的内容,我将不胜感激!:)
您使用的是相对路径,因为database.php
和functions.php
在includes
文件夹中,您可以删除includes
路径中的部分。
IE:
database.php
<?php
session_start();
require_once('functions.php');
?>
functions.php
<?php require_once('database.php');?>
另一种方法是在包含/需要时使用绝对路径(我更喜欢这种方式)
IE:
database.php
<?php
session_start();
require_once(__DIR__ . '/../includes/functions.php');
?>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句