Search code examples
phprequire

' ../ ' not working in php


I have a file frontend/file.php and I want to include a file (using require function) in database/file2.php (frontend and database folders are in the same directory) I wrote this code:

require('../database/file2.php');

But it isnt working, please help


Solution

  • Use this:

    require __DIR__ . '/../database/file2.php';
    

    This will ensure the file is located relative to the current path, read more about this here.

    PHP Require Guide