diff options
author | redmatrix <redmatrix@redmatrix.me> | 2015-05-18 09:41:53 +1000 |
---|---|---|
committer | redmatrix <redmatrix@redmatrix.me> | 2015-05-18 09:41:53 +1000 |
commit | 7233967ad5c1e934b7c23e37a7c0bb66a4ed325d (patch) | |
tree | f45c604a7921b14cc4a25099d4af9d61b7458459 /include/environment.php | |
parent | 1cca24dfdc4ee500132435d55d2f5840b9fc39d1 (diff) | |
parent | e2980e871fd9d7e769cf19b58c03574d386e542e (diff) | |
download | volse-hubzilla-7233967ad5c1e934b7c23e37a7c0bb66a4ed325d.tar.gz volse-hubzilla-7233967ad5c1e934b7c23e37a7c0bb66a4ed325d.tar.bz2 volse-hubzilla-7233967ad5c1e934b7c23e37a7c0bb66a4ed325d.zip |
Merge pull request #322 from dawnbreak/master
Add functions to parse and get some values from php.ini.
Diffstat (limited to 'include/environment.php')
-rw-r--r-- | include/environment.php | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/include/environment.php b/include/environment.php new file mode 100644 index 000000000..47ad241a7 --- /dev/null +++ b/include/environment.php @@ -0,0 +1,66 @@ +<?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; + } + + return (int)$val; +}
\ No newline at end of file |