duanfei8399 2019-04-05 19:01
浏览 113
已采纳

安装Braintree并收到错误“Uncaught InvalidArgumentException:Dotenv:Environment file .env not found or not readable。”

I'm trying to get Braintree working on my local Ubuntu environment and I'm getting the error Uncaught InvalidArgumentException: Dotenv: Environment file .env not found or not readable. I think its relating to the backslash in the code below. I'm not sure how to fix it though, can anyone help with this?

This is the error I'm receiving:

[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
Stack trace:
#0 /var/www/html/myskinpro/vendor/vlucas/phpdotenv/src/Loader.php(51): Dotenv\\Loader->ensureFileIsReadable()
#1 /var/www/html/myskinpro/vendor/vlucas/phpdotenv/src/Dotenv.php(41): Dotenv\\Loader->load()
#2 /var/www/html/myskinpro/includes/braintree_init.php(7): Dotenv\\Dotenv->load()
#3 /var/www/html/myskinpro/payusd/index.php(1): require_once('/var/www/html/m...')
#4 {main}
  thrown in /var/www/html/myskinpro/vendor/vlucas/phpdotenv/src/Loader.php on line 78

This is the code that's causing the problem:

<?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')
]);
  • 写回答

1条回答 默认 最新

  • dqy012345 2019-04-06 12:49
    关注

    This code fixes the issue:

    if(file_exists(__DIR__ . "/../example.env")) {
        $dotenv = new Dotenv\Dotenv(__DIR__ . "/../", 'example.env');
        $dotenv->load();
    } else {
      echo "file does not exist";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器