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 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用