fix #71 find config.php automatically in current and parent directories. Show error message if not found.
This commit is contained in:
parent
320e4e68cf
commit
32c9a172d2
|
@ -1,6 +1,9 @@
|
||||||
# Change Log
|
# Change Log
|
||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- find config.php automatically in current and parent directories. Show error message if not found.
|
||||||
|
|
||||||
The format is based on [Keep a Changelog](http://keepachangelog.com/).
|
The format is based on [Keep a Changelog](http://keepachangelog.com/).
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
39
src/boot.php
Normal file
39
src/boot.php
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
<?php
|
||||||
|
if (version_compare(phpversion(), '7.2', '<')) {
|
||||||
|
die("ERROR! The php version isn't high enough, you need at least 7.2 to run this application! But you have: " . phpversion());
|
||||||
|
}
|
||||||
|
|
||||||
|
# set the new path of config.php (must be in a safe location outside the `public_html`)
|
||||||
|
#require_once '../../config.php';
|
||||||
|
|
||||||
|
function find_config($filename='config.php'){
|
||||||
|
$path_length = substr_count(getcwd(),DIRECTORY_SEPARATOR)
|
||||||
|
+ 1; # also search the current directory
|
||||||
|
|
||||||
|
$dir = '.';
|
||||||
|
for($i=0; $i<$path_length;$i++){
|
||||||
|
$config_filename = $dir . DIRECTORY_SEPARATOR . $filename;
|
||||||
|
if(file_exists($config_filename)){
|
||||||
|
return $config_filename;
|
||||||
|
} else {
|
||||||
|
$dir = '../'.$dir;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
function load_config(){
|
||||||
|
global $config;
|
||||||
|
$file = find_config();
|
||||||
|
if ( $file !== FALSE) {
|
||||||
|
require_once($file);
|
||||||
|
} else {
|
||||||
|
die('ERROR: Config file not found. Please see the installation instructions in the README.md');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
load_config();
|
||||||
|
|
||||||
|
# load php dependencies:
|
||||||
|
require_once './backend-libs/autoload.php';
|
||||||
|
|
|
@ -3,11 +3,8 @@ if (version_compare(phpversion(), '7.2', '<')) {
|
||||||
die("ERROR! The php version isn't high enough, you need at least 7.2 to run this application! But you have: " . phpversion());
|
die("ERROR! The php version isn't high enough, you need at least 7.2 to run this application! But you have: " . phpversion());
|
||||||
}
|
}
|
||||||
|
|
||||||
# set the new path of config.php (must be in a safe location outside the `public_html`)
|
# load config file and dependencies
|
||||||
require_once '../../config.php';
|
require_once './boot.php';
|
||||||
|
|
||||||
# load php dependencies:
|
|
||||||
require_once './backend-libs/autoload.php';
|
|
||||||
|
|
||||||
require_once './user.php';
|
require_once './user.php';
|
||||||
require_once './imap_client.php';
|
require_once './imap_client.php';
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
# set the new path of config.php (must be in a safe location outside the `public_html`)
|
|
||||||
require_once '../../config.php';
|
|
||||||
|
|
||||||
# load php dependencies:
|
# load config file and dependencies
|
||||||
require_once 'backend-libs/autoload.php';
|
require_once './boot.php';
|
||||||
|
|
||||||
require_once 'user.php';
|
require_once 'user.php';
|
||||||
require_once 'imap_client.php';
|
require_once 'imap_client.php';
|
||||||
|
|
Loading…
Reference in New Issue
Block a user