Home > Software design >  Why am getting the error `failed to open stream: No such file or directory`?
Why am getting the error `failed to open stream: No such file or directory`?

Time:02-08

for the beolw code, am getting the warning - require_once(C:\xampp\htdocs\abcd\application\controllers/vendor/autoload.php): failed to open stream: No such file or directory. I've no idea why this error comes here, becoz the autoload.php file exists in vendor folder.And the folder is existing in the root directory.composer_autoload is true in config\autoload.php. Can someone tell me the possible causes of this issue?Anyhelp is much appreciated.

controller

<?php

if (!defined('BASEPATH')) exit('No direct script access allowed');

require_once __DIR__ . '/vendor/autoload.php';
//require_once __DIR__ . '\vendor\autoload.php'; //also tried reversing the slashes like this

class Reports extends Layout_Controller
{

}

vendor\autoload.php

composer install error

enter image description here

CodePudding user response:

It looks like you are using unix based directory seperators on Windows. I suggest you to use the php constant DIRECTORY_SEPARATOR:

...
require_once implode([__DIR__, 'composer', 'autoload_real.php'], DIRECTORY_SEPARATOR);

This was automatically generated by composer so you can also run:

composer dump-autoload

in Windows to generate it with the correct Windows style paths.

CodePudding user response:

I had the same issue with require_once __DIR__ . '../../vendor/autoload.php'; , edited @Mark's answer as follows

require_once implode(DIRECTORY_SEPARATOR, [__DIR__, 'vendor/composer', 'vendor/autoload.php']);

and it worked!

  •  Tags:  
  • Related