aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorKlaus Weidenbach <Klaus.Weidenbach@gmx.net>2015-05-16 11:12:39 +0200
committerKlaus Weidenbach <Klaus.Weidenbach@gmx.net>2015-05-16 11:25:32 +0200
commite2980e871fd9d7e769cf19b58c03574d386e542e (patch)
tree61a6acfce6e06c0b96b5d1c7f66a5ed5edb44711 /include
parent70fa00c014fcdbb666ac870873024c41b6609191 (diff)
downloadvolse-hubzilla-e2980e871fd9d7e769cf19b58c03574d386e542e.tar.gz
volse-hubzilla-e2980e871fd9d7e769cf19b58c03574d386e542e.tar.bz2
volse-hubzilla-e2980e871fd9d7e769cf19b58c03574d386e542e.zip
Add functions to parse and get some values from php.ini.
Get upload limits from php.ini. These functions will be used for checking against upload limits and to give information in the frontend. Wasn't sure in which file to put these functions, so I created a new one include/environment.php.
Diffstat (limited to 'include')
-rw-r--r--include/environment.php66
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