commit 3a9422ff8c8c15d9d80c393146d4f0a88235de47
parent 92a7cade1a9194731a5cf836abd97e5b59d74cac
Author: dankert <devnull@localhost>
Date: Mon, 1 Oct 2007 23:43:59 +0200
Ermitteln der maximalen Dateigroesse bei Uploads.
Diffstat:
2 files changed, 85 insertions(+), 5 deletions(-)
diff --git a/actionClasses/FolderAction.class.php b/actionClasses/FolderAction.class.php
@@ -20,6 +20,9 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// ---------------------------------------------------------------------------
// $Log$
+// Revision 1.39 2007-10-01 21:43:42 dankert
+// Ermitteln der maximalen Dateigroesse bei Uploads.
+//
// Revision 1.38 2007-07-02 20:14:07 dankert
// Ordnerinhalte rekursiv l?schen (also samt Unterordnern)
//
@@ -702,12 +705,75 @@ class FolderAction extends ObjectAction
}
-
+
+ /**
+ * Ermittelt die maximale Größe einer hochzuladenden Datei.<br>
+ * Der Wert wird aus der PHP-Konfiguration ermittelt.
+ *
+ * @return Integer maximale Dateigroesse in Kilobytes
+ */
+ function maxFileSize()
+ {
+ // When querying memory size values:
+ // Many ini memory size values, such as upload_max_filesize,
+ // are stored in the php.ini file in shorthand notation.
+ // ini_get() will return the exact string stored in the php.ini file
+ // and NOT its integer equivalent.
+ $sizes = array();
+ foreach( array('upload_max_filesize','post_max_size','memory_limit') as $var )
+ {
+ $v = $this->stringToBytes(ini_get($var));
+
+ if ($v > 0 )
+ $sizes[] = $v;
+ }
+
+ return min($sizes);
+ }
+
+
+ /**
+ * Hochladen einer Datei.
+ *
+ */
function createfile()
- {
- $this->setTemplateVar('objectid' ,$this->folder->objectid );
+ {
+ // Maximale Dateigroesse.
+ $this->setTemplateVar('max_size',($this->maxFileSize()/1024).' KB' );
+
+ $this->setTemplateVar('objectid',$this->folder->objectid );
}
-
+
+
+ /**
+ * Umwandlung von abgekürzten Bytewerten ("Shorthand Notation") wie
+ * "4M" oder "500K" in eine ganzzahlige Byteanzahl.<br>
+ * <br>
+ * Quelle: http://de.php.net/manual/de/function.ini-get.php
+ *
+ * @param String Abgekürzter Bytewert
+ * @return Integer Byteanzahl
+ */
+ function stringToBytes($val)
+ {
+ $val = trim($val);
+ $last = strtolower($val{strlen($val)-1});
+ // Achtung: Der Trick ist das "Fallthrough", kein "break" vorhanden!
+ switch($last)
+ {
+ // The 'G' modifier is available since PHP 5.1.0
+ case 'g':
+ $val *= 1024;
+ case 'm':
+ $val *= 1024;
+ case 'k':
+ $val *= 1024;
+ }
+
+ return intval($val);
+ }
+
+
function createlink()
{
diff --git a/themes/default/templates/folder/createfile.tpl.src.php b/themes/default/templates/folder/createfile.tpl.src.php
@@ -3,11 +3,24 @@ page
hidden name:type default:file
window title: name:
+ row
+ cell colspan:2
+ fieldset title:message:file
row
cell class:fx
text text:global_FILE
cell class:fx
- upload name:file
+ upload name:file
+ row
+ cell colspan:2
+ text class:help text:message:file_max_size
+ text raw:_
+ text text:var:max_size
+ newline
+ newline
+ row
+ cell colspan:2
+ fieldset title:message:description
row
cell class:fx
text text:global_NAME
@@ -18,6 +31,7 @@ page
text text:global_DESCRIPTION
cell class:fx
inputarea rows:5 cols:50 name:description
+ newline
row
cell class:act colspan:2
button type:ok