vendor/autoload.php: 打开流失败

vendor/autoload.php: failed to open stream

我使用 composer.But 处理一个项目,当我 运行 索引文件时,系统显示以下错误,

Warning: require_once(vendor/autoload.php): failed to open stream: No such file or directory in D:\xampp\htdocs\instagram_php\index.php on line 5

Fatal error: require_once(): Failed opening required 'vendor/autoload.php' (include_path='.;D:\xampp\php\PEAR') in D:\xampp\htdocs\instagram_php\index.php on line 5

我已经从 https://getcomposer.org/ 安装了作曲家。 哪里做错了?

您正在require_once使用相对路径。这是可能的,但有太多可能出错的地方,我通常会避免它。

相对于 index.phpvendor 文件夹在哪里?我建议使用绝对路径。您可以使用魔术常量来确定它:

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

注意:您可以使用 /.. 向上目录树。

注意 2:__DIR__ 需要 php 5.3 或更高版本。您可以对旧版本使用 dirname(__FILE__)

确保 vendor 文件夹存在,如果不存在,请 运行 以下命令:-

composer install