php - Rest api: having trouble with root path directoryGet the solution ↓↓↓
I am pretty sure Im writing the directory wrong.
This is the error Im getting on Postman:
Warning: require_once(./includes/functions.php): failed to open stream: No such file or directory in /var/www/html/includes/database.php on line 3
Fatal error: require_once(): Failed opening required './includes/functions.php' (include_path='.:/usr/local/lib/php') in /var/www/html/includes/database.php on line 3
My file structure:
PHP _api/ __index.php _includes/ __database.php __functions.php
My index.php file:
<?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(); ?>
The require_once in the database.php file:
<?php session_start(); require_once('./includes/functions.php'); ?>
And in functions.php:
If somebody can help me to find what Im missing on my code I'll appreciate! :)
You are using relative path and because
functions.php are in the
includes folder, you can just remove the
includes part in the path.
database.php <?php session_start(); require_once('functions.php'); ?>
functions.php <?php require_once('database.php');?>
Another way to do this is to use absolute path when your include/require (I prefer this way)
database.php <?php session_start(); require_once(__DIR__ . '/../includes/functions.php'); ?>
People are also looking for solutions of the problem: uncaught error: call to undefined function mysqli_connect()
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.