Autoload Error: No such file or directory
Asked Answered
G

3

5

I have included autoload.php in the header of my site

include 'vendor/autoload.php'; 

From this i am receiving the following errors on my site:

Warning: require_once(DIR/composer/autoload_real.php) [function.require-once]: failed to open stream: No such file or directory in /homepages/6/d416629391/htdocs/leftovercheese/vendor/autoload.php on line 5

Fatal error: require_once() [function.require]: Failed opening required 'DIR/composer/autoload_real.php' (include_path='.:/usr/lib/php5') in /homepages/6/d416629391/htdocs/leftovercheese/vendor/autoload.php on line 5

My code is:

// autoload.php generated by Composer

require_once __DIR__ . '/composer' . '/autoload_real.php';

return ComposerAutoloaderInit8be239f5caef32db03f87bb271ed6012::getLoader();

PHP Version: 5.2.17

Any ideas?

Guib answered 23/8, 2013 at 15:3 Comment(0)
D
5

You have to load vendor/autoload.php, which will autoload that file for you:

require_once __DIR__ . '/vendor/autoload.php';

This is assuming that your file is located at the same directory level as the vendor directory.

Otherwise, adjust.

Dimidiate answered 23/8, 2013 at 15:4 Comment(3)
I have included the autoload.php file, I think the original error message is a result of including the autoload.Guib
The two files are located: vendor\autoload.php vendor\composer\autoload_real.phpGuib
The version of PHP i was using did not support DIR. Instead use FILE, as shown below. > DIR The directory of the file. If used inside an include, the directory of the included file is returned. This is equivalent to > dirname(FILE). This directory name does not have a trailing slash > unless it is the root directory. (Added in PHP 5.3.0.)Guib
H
11

run composer install

That will import your packages and create the vendor folder as well as the autoload script. Also, make sure your relative path is correct.

Harmaning answered 15/6, 2018 at 9:41 Comment(1)
running composer update helped me .Mchugh
D
5

You have to load vendor/autoload.php, which will autoload that file for you:

require_once __DIR__ . '/vendor/autoload.php';

This is assuming that your file is located at the same directory level as the vendor directory.

Otherwise, adjust.

Dimidiate answered 23/8, 2013 at 15:4 Comment(3)
I have included the autoload.php file, I think the original error message is a result of including the autoload.Guib
The two files are located: vendor\autoload.php vendor\composer\autoload_real.phpGuib
The version of PHP i was using did not support DIR. Instead use FILE, as shown below. > DIR The directory of the file. If used inside an include, the directory of the included file is returned. This is equivalent to > dirname(FILE). This directory name does not have a trailing slash > unless it is the root directory. (Added in PHP 5.3.0.)Guib
S
1

For me, I updated some folder names and these updated are not reflected in autoload_files.php and autoload_static.php. I just had to run php composer.phar dump-autoload.

Sherl answered 23/3, 2021 at 20:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.