mirror of
https://codeberg.org/streams/streams.git
synced 2024-09-20 00:35:30 +00:00
move everything from include/environment to setup where it is used
This commit is contained in:
parent
cb2a64b036
commit
6bdf35ec67
2 changed files with 63 additions and 70 deletions
|
@ -451,11 +451,10 @@ class Setup extends Controller {
|
|||
* @param[out] array &$checks
|
||||
*/
|
||||
function check_phpconfig(&$checks) {
|
||||
require_once 'include/environment.php';
|
||||
|
||||
$help = '';
|
||||
|
||||
$result = getPhpiniUploadLimits();
|
||||
$result = self::getPhpiniUploadLimits();
|
||||
if($result['post_max_size'] < (2 * 1024 * 1024) || $result['max_upload_filesize'] < (2 * 1024 * 1024)) {
|
||||
$mem_warning = '<strong>' . t('This is not sufficient to upload larger images or files. You should be able to upload at least 2MB (2097152 bytes) at once.') . '</strong>';
|
||||
}
|
||||
|
@ -798,4 +797,66 @@ class Setup extends Controller {
|
|||
return $v;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get some upload related limits from php.ini.
|
||||
*
|
||||
* This function returns values from php.ini like \b post_max_size,
|
||||
* \b max_file_uploads, \b upload_max_filesize.
|
||||
*
|
||||
* @return array associative array
|
||||
* * \e int \b post_max_size the maximum size of a complete POST in bytes
|
||||
* * \e int \b upload_max_filesize the maximum size of one file in bytes
|
||||
* * \e int \b max_file_uploads maximum number of files in one POST
|
||||
* * \e int \b max_upload_filesize min(post_max_size, upload_max_filesize)
|
||||
*/
|
||||
|
||||
static private function getPhpiniUploadLimits() {
|
||||
$ret = array();
|
||||
|
||||
// max size of the complete POST
|
||||
$ret['post_max_size'] = self::phpiniSizeToBytes(ini_get('post_max_size'));
|
||||
// max size of one file
|
||||
$ret['upload_max_filesize'] = self::phpiniSizeToBytes(ini_get('upload_max_filesize'));
|
||||
// catch a configuration error where post_max_size < upload_max_filesize
|
||||
$ret['max_upload_filesize'] = min(
|
||||
$ret['post_max_size'],
|
||||
$ret['upload_max_filesize']
|
||||
);
|
||||
// maximum number of files in one POST
|
||||
$ret['max_file_uploads'] = intval(ini_get('max_file_uploads'));
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Parses php_ini size settings to bytes.
|
||||
*
|
||||
* This function parses common size setting from php.ini files to bytes.
|
||||
* e.g. post_max_size = 8M ==> 8388608
|
||||
*
|
||||
* \note This method does not recognise other human readable formats like
|
||||
* 8MB, etc.
|
||||
*
|
||||
* @todo Make this function more universal useable. MB, T, etc.
|
||||
*
|
||||
* @param string $val value from php.ini e.g. 2M, 8M
|
||||
* @return int size in bytes
|
||||
*/
|
||||
static private function phpiniSizeToBytes($val) {
|
||||
$val = trim($val);
|
||||
$unit = strtolower($val[strlen($val)-1]);
|
||||
switch($unit) {
|
||||
case 'g':
|
||||
$val *= 1024;
|
||||
case 'm':
|
||||
$val *= 1024;
|
||||
case 'k':
|
||||
$val *= 1024;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return (int)$val;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,68 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @file include/environment.php
|
||||
* @brief Functions related to system/environment tasks.
|
||||
*
|
||||
* This file contains some functions to check the environment/system.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Get some upload related limits from php.ini.
|
||||
*
|
||||
* This function returns values from php.ini like \b post_max_size,
|
||||
* \b max_file_uploads, \b upload_max_filesize.
|
||||
*
|
||||
* @return array associative array
|
||||
* * \e int \b post_max_size the maximum size of a complete POST in bytes
|
||||
* * \e int \b upload_max_filesize the maximum size of one file in bytes
|
||||
* * \e int \b max_file_uploads maximum number of files in one POST
|
||||
* * \e int \b max_upload_filesize min(post_max_size, upload_max_filesize)
|
||||
*/
|
||||
function getPhpiniUploadLimits() {
|
||||
$ret = array();
|
||||
|
||||
// max size of the complete POST
|
||||
$ret['post_max_size'] = phpiniSizeToBytes(ini_get('post_max_size'));
|
||||
// max size of one file
|
||||
$ret['upload_max_filesize'] = phpiniSizeToBytes(ini_get('upload_max_filesize'));
|
||||
// catch a configuration error where post_max_size < upload_max_filesize
|
||||
$ret['max_upload_filesize'] = min(
|
||||
$ret['post_max_size'],
|
||||
$ret['upload_max_filesize']
|
||||
);
|
||||
// maximum number of files in one POST
|
||||
$ret['max_file_uploads'] = intval(ini_get('max_file_uploads'));
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Parses php_ini size settings to bytes.
|
||||
*
|
||||
* This function parses common size setting from php.ini files to bytes.
|
||||
* e.g. post_max_size = 8M ==> 8388608
|
||||
*
|
||||
* \note This method does not recognise other human readable formats like
|
||||
* 8MB, etc.
|
||||
*
|
||||
* @todo Make this function more universal useable. MB, T, etc.
|
||||
*
|
||||
* @param string $val value from php.ini e.g. 2M, 8M
|
||||
* @return int size in bytes
|
||||
*/
|
||||
function phpiniSizeToBytes($val) {
|
||||
$val = trim($val);
|
||||
$unit = strtolower($val[strlen($val)-1]);
|
||||
switch($unit) {
|
||||
case 'g':
|
||||
$val *= 1024;
|
||||
case 'm':
|
||||
$val *= 1024;
|
||||
case 'k':
|
||||
$val *= 1024;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return (int)$val;
|
||||
}
|
Loading…
Reference in a new issue