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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)