laravel 尝试 require_once('vendor/autoload.php') 时,无法打开所需的 'vendor/autoload.php' 错误;

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37908520/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 14:01:34  来源:igfitidea点击:

Failed opening required 'vendor/autoload.php' error when trying require_once('vendor/autoload.php');

phplaravellaravel-5composer-phpstripe-payments

提问by LaserBeak

Trying to get Stripe library up and running. Get failed opening required 'vendor/autoload.php' error.

尝试启动并运行 Stripe 库。获取失败打开所需的“vendor/autoload.php”错误。

autoload.php is there in /vendor

/vendor 中有 autoload.php

ran composer update, then composer install , didn't help.

运行 composer update ,然后 composer install ,没有帮助。

config.php

配置文件

    <?php

require_once('vendor/autoload.php');

    $stripe = array(
      "secret_key"      => "XXXXXXXXXXXXXXXXXXXXXX",
      "publishable_key" => "XXXXXXXXXXXXXXXXXXXXXX"
    );

    \Stripe\Stripe::setApiKey($stripe['secret_key']);

?>

autoload.php

自动加载.php

<?php

// autoload.php @generated by Composer

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

    return ComposerAutoloaderInit18eff69591fc6597a849a05ec4932261::getLoader();

回答by Jeff Puckett

It looks like a problem with your relative path. Because this "script is in /app/modules/stripe"and the vendor folder "is /vendor", then you can use the constant __DIR__to reference the included script's location, and then up 3 relative directories.

看起来你的相对路径有问题。因为这个“脚本在/app/modules/stripe和供应商文件夹“是/vendor,那么你可以使用常量__DIR__来引用包含脚本的位置,然后向上3个相关目录。

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

回答by Muhammad Sumon Molla Selim

Try to change the require_once to this:

尝试将 require_once 更改为:

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

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

回答by Rudra Sarkar

try this.Work for me.

试试这个。对我来说有效。

composer update --no-scripts