Home > database >  Failed to open stream: No such file or directory, when using __DIR__
Failed to open stream: No such file or directory, when using __DIR__

Time:09-09

PHP is throwing this error when trying to access autoload: require_once __DIR__ . '/../vendor/autoload.php';

Warning: require_once(/Applications/MAMP/htdocs/crud_app/public/vendor/autoload.php): Failed to open stream: No such file or directory in /Applications/MAMP/htdocs/crud_app/public/index.php on line 6

The thing is that if I echo __DIR__.'/../vendor/autoload.php'; it shows /Applications/MAMP/htdocs/crud_app/public and the vendor directory is outside of public. This is the path where autoload.php is:

/Applications/MAMP/htdocs/crud_app/controllers/vendor/autoload.php

Any idea what is happening? This is my repo in case you want to look at it. Running PHP 8.1 and macOS. Thanks in advance.

CodePudding user response:

index.php isn't inside controllers, you need to add that to the path.

require_once __DIR__ . '/../controllers/vendor/autoload.php';
  • Related