From d0ccfa4b9895b7f8b9afe3ebcee12b89df7c9017 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Tue, 4 Mar 2008 16:53:14 +0000 Subject: [PATCH] added checks and messages for failed uploads because of to small max_upload_size and post_max_size (memory_limit plays no role any more using the new vfs stuff) --- filemanager/inc/class.filemanager_ui.inc.php | 56 ++++++++++++++++++-- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/filemanager/inc/class.filemanager_ui.inc.php b/filemanager/inc/class.filemanager_ui.inc.php index e151f34f33..02b907b606 100644 --- a/filemanager/inc/class.filemanager_ui.inc.php +++ b/filemanager/inc/class.filemanager_ui.inc.php @@ -9,7 +9,7 @@ * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License * @version $Id$ */ - +error_log(__FILE__); class filemanager_ui { /** @@ -63,6 +63,14 @@ class filemanager_ui } if (isset($_GET['msg'])) $msg = $_GET['msg']; } + // check if we have a failed upload AND upload_max_filesize >= post_max_size --> no $_POST array + if ($_GET['post_empty'] && self::km2int(ini_get('upload_max_filesize')) >= self::km2int(ini_get('post_max_size')) || + // or size bigger as upload_max_filesize + $content['button']['upload'] && (!is_array($content['upload']) || !is_uploaded_file($content['upload']['tmp_name']))) + { + $msg = lang('Error uploading file!')."\n".self::max_upload_size_message(); + unset($content['button']); + } $content['nm']['msg'] = $msg; if ($content['action'] || $content['nm']['rows']) @@ -145,8 +153,8 @@ class filemanager_ui $dir_is_writable = egw_vfs::is_writable($content['nm']['path']); } $content['paste_tooltip'] = $clipboard_files ? '

'.lang('%1 the following files into current directory', - $clipboard_type=='copy'?lang('Copy'):lang('Move')).':
'.implode('
',$clipboard_files).'

' : - ''; + $clipboard_type=='copy'?lang('Copy'):lang('Move')).':
'.implode('
',$clipboard_files).'

' : ''; + $content['upload_size'] = self::max_upload_size_message(); //_debug_array($content); $readonlys['button[paste]'] = !$clipboard_files; @@ -163,7 +171,47 @@ class filemanager_ui ); $tpl->exec('filemanager.filemanager_ui.index',$content,$sel_options,$readonlys,array('nm' => $content['nm'])); } - + + /** + * Convert numbers like '32M' or '512k' to integers + * + * @param string $size + * @return int + */ + private static function km2int($size) + { + if (!is_numeric($size)) + { + switch(strtolower(substr($size,-1))) + { + case 'm': + $size = 1024*1024*(int)$size; + break; + case 'k': + $size = 1024*(int)$size; + break; + } + } + return (int)$size; + } + + /** + * Message containing the max Upload size from the current php.ini settings + * + * We have to take the smaler one of upload_max_filesize AND post_max_size-2800 into account. + * memory_limit does NOT matter any more, because of the stream-interface of the vfs. + * + * @return string + */ + static function max_upload_size_message() + { + $upload_max_filesize = ini_get('upload_max_filesize'); + $post_max_size = ini_get('post_max_size'); + $max_upload = min(self::km2int($upload_max_filesize),self::km2int($post_max_size)-2800); + + return lang('Maximum size for uploads: %1 (php.ini: upload_max_filesize=%2, post_max_size=%3)',egw_vfs::hsize($max_upload),$upload_max_filesize,$post_max_size); + } + /** * Run a certain action with the selected file *