安装 Braintree 并出现错误 "Uncaught InvalidArgumentException: Dotenv: Environment file .env not found or not readable."

Installing Braintree and getting error "Uncaught InvalidArgumentException: Dotenv: Environment file .env not found or not readable."

我试图让 Braintree 在我的本地 Ubuntu 环境中工作,但我收到错误 Uncaught InvalidArgumentException: Dotenv: Environment file .env not found or not readable. 我认为它与下面代码中的反斜杠有关。不过我不确定如何解决它,有人可以帮忙吗?

这是我收到的错误:

[Fri Apr 05 14:14:26.170718 2019] [php7:error] [pid 88156] [client ::1:52042] PHP Fatal error:  Uncaught InvalidArgumentException: Dotenv: Environment file .env not found or not readable. Create file with your environment settings at /var/www/html/myskinpro/includes/../example.env/.env in /var/www/html/myskinpro/vendor/vlucas/phpdotenv/src/Loader.php:78\nStack trace:\n#0 /var/www/html/myskinpro/vendor/vlucas/phpdotenv/src/Loader.php(51): Dotenv\Loader->ensureFileIsReadable()\n#1 /var/www/html/myskinpro/vendor/vlucas/phpdotenv/src/Dotenv.php(41): Dotenv\Loader->load()\n#2 /var/www/html/myskinpro/includes/braintree_init.php(7): Dotenv\Dotenv->load()\n#3 /var/www/html/myskinpro/payusd/index.php(1): require_once('/var/www/html/m...')\n#4 {main}\n  thrown in /var/www/html/myskinpro/vendor/vlucas/phpdotenv/src/Loader.php on line 78

这是导致问题的代码:

<?php
session_start();
require_once("../vendor/autoload.php");

if(file_exists(__DIR__ . "/../example.env")) {
    $dotenv = new Dotenv\Dotenv(__DIR__ . "/../example.env");
    $dotenv->load();
} else {
  echo "file does not exist";
}

$gateway = new Braintree\Gateway([
    'environment' => getenv('BT_ENVIRONMENT'),
    'merchantId' => getenv('BT_MERCHANT_ID'),
    'publicKey' => getenv('BT_PUBLIC_KEY'),
    'privateKey' => getenv('BT_PRIVATE_KEY')
]);

此代码修复了问题:

if(file_exists(__DIR__ . "/../example.env")) {
    $dotenv = new Dotenv\Dotenv(__DIR__ . "/../", 'example.env');
    $dotenv->load();
} else {
  echo "file does not exist";
}