0

我正在尝试让 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')
]);
4

1 回答 1

0

这段代码解决了这个问题:

if(file_exists(__DIR__ . "/../example.env")) {
    $dotenv = new Dotenv\Dotenv(__DIR__ . "/../", 'example.env');
    $dotenv->load();
} else {
  echo "file does not exist";
}
于 2019-04-06T12:49:53.373 回答