vendor/autoload.php:无法打开流

Uma*_*Uma 3 php instagram-api

我使用 Composer 处理一个项目。但是当我运行索引文件时,系统显示以下错误,

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
Run Code Online (Sandbox Code Playgroud)

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

Rad*_*d80 6

您正在使用require_once相对路径。这是可能的,但有很多事情可能会出错,所以我通常会避免它。

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

require_once(__DIR__ . '/vendor/autoload.php');
Run Code Online (Sandbox Code Playgroud)

注意:您可以使用/..进入目录树。

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