moved failed upload check from filemanager to etemplate and further improved it

This commit is contained in:
Ralf Becker 2010-02-05 02:54:47 +00:00
parent 75746226a4
commit 6fb9ae3a6d
24 changed files with 88 additions and 71 deletions

View File

@ -426,7 +426,23 @@ class etemplate extends boetemplate
if ($this->sitemgr) return false;
//echo "uitemplate::process_exec() id='$_POST[etemplate_exec_id]' invalid session-data !!!"; _debug_array($_SESSION);
// this prevents an empty screen, if the sessiondata gets lost somehow
$this->location(array('menuaction' => $_GET['menuaction'],'post_empty' => (int)!$_POST));
$redirect = array(
'menuaction' => $_GET['menuaction'],
);
if (!$_POST && $_SERVER['REQUEST_METHOD'] == 'POST')
{
$redirect['post_empty'] = 1;
// check if we have a failed upload, because user tried to uploaded a file
// bigger then php.ini setting post_max_size
// in that case the webserver calls PHP with $_POST === array()
if (substr($_SERVER['CONTENT_TYPE'],0,19) == 'multipart/form-data' &&
$_SERVER['CONTENT_LENGTH'] > self::km2int(ini_get('post_max_size')))
{
$redirect['failed_upload'] = 1;
$redirect['msg'] = lang('Error uploading file!')."\n".self::max_upload_size_message();
}
}
$this->location($redirect);
}
self::$name_vars = self::$request->name_vars;
if (isset($submit_button) && !empty($submit_button))
@ -522,6 +538,47 @@ class etemplate extends boetemplate
}
}
/**
* 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').': '.egw_vfs::hsize($max_upload).
" (php.ini: upload_max_filesize=$upload_max_filesize, post_max_size=$post_max_size)";
}
/**
* 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;
}
/**
* process the values transfered with the javascript function values2url
*
@ -2166,6 +2223,12 @@ class etemplate extends boetemplate
}
if (!$multiple) $file['path'] = $this->get_array($content_in,substr($form_name,0,-1).'_path]');
$file['ip'] = $_SERVER['REMOTE_ADDR'];
// check if we have an upload error
if ($file['error'] && $file['name'] !== '' && !$file['size']) // ignore empty upload boxes
{
self::set_validation_error($form_name.($multiple?'[]':''),
lang('Error uploading file!')."\n".self::max_upload_size_message(),'');
}
if ((string)$file['name'] === '' || $file['tmp_name'] && function_exists('is_uploaded_file') && !is_uploaded_file($file['tmp_name']))
{
if ($multiple && ($file['name'] === '' || $file['error']))

View File

@ -0,0 +1,2 @@
error uploading file! filemanager bg Грешка при качване на файла!
maximum size for uploads filemanager bg Максимален размер за качване

View File

@ -420,3 +420,5 @@ xslt template etemplate cs XSLT šablona
year etemplate cs Rok
you are not allowed to export more then %1 entries! etemplate cs Nemáte oprávnění exportovat více než %1 záznamů!
you can respond by visiting: etemplate cs Můžete odpovědět navštívením:
error uploading file! filemanager cs Chyba při uploadu souboru!
maximum size for uploads filemanager cs Maximální velikost pro uploady

View File

@ -420,3 +420,5 @@ xslt template etemplate de XSLT Template
year etemplate de Jahr
you are not allowed to export more then %1 entries! etemplate de Sie sind nicht berechtigt mehr als %1 Datensätze zu exportieren!
you can respond by visiting: etemplate de Sie können unter dem folgenden Verweis antworten:
error uploading file! filemanager de Fehler beim Hochladen der Datei!
maximum size for uploads filemanager de Maximale Größe beim Hochladen

View File

@ -420,3 +420,5 @@ xslt template etemplate en XSLT Template
year etemplate en Year
you are not allowed to export more then %1 entries! etemplate en You are not allowed to export more then %1 entries!
you can respond by visiting: etemplate en You can respond by visiting:
error uploading file! filemanager en Error uploading file!
maximum size for uploads filemanager en Maximum size for uploads

View File

@ -412,3 +412,5 @@ xslt template etemplate es-es Plantilla XSLT
year etemplate es-es Año
you are not allowed to export more then %1 entries! etemplate es-es ¡No se le permite exportar más de %1 entradas!
you can respond by visiting: etemplate es-es Puede responder visitando:
error uploading file! filemanager es-es ¡Error al subir el fichero!
maximum size for uploads filemanager es-es Tamaño máximo para subida de ficheros

View File

@ -81,3 +81,5 @@ weekend etemplate hu hétvége
width etemplate hu Szélesség
working days etemplate hu munkanapok
year etemplate hu Év
error uploading file! filemanager hu HIba a file feltöltése során!
maximum size for uploads filemanager hu Feltöltés maximális mérete

View File

@ -412,3 +412,5 @@ xslt template etemplate nl XSLT Template
year etemplate nl Jaar
you are not allowed to export more then %1 entries! etemplate nl Je mag niet meer dan %1 items exporteren!
you can respond by visiting: etemplate nl Ju kunt reageren via:
error uploading file! filemanager nl Fout bij uploaden van bestand!
maximum size for uploads filemanager nl Maximum grootte voor uploads

View File

@ -412,3 +412,5 @@ xslt template etemplate pt-br Modelo XSLT
year etemplate pt-br Ano
you are not allowed to export more then %1 entries! etemplate pt-br Você não tem permissão para exportar mais de %1 registros!
you can respond by visiting: etemplate pt-br Você pode responder acessando:
error uploading file! filemanager pt-br Erro carregando arquivo!
maximum size for uploads filemanager pt-br Tamanho máximo para uploads

View File

@ -387,3 +387,5 @@ xslt template etemplate sk XSLT šablóna
year etemplate sk Rok
you are not allowed to export more then %1 entries! etemplate sk Nie je vám dovolené, exportovať viac než %1 záznamov!
you can respond by visiting: etemplate sk Odpovedať môžete na tejto adrese:
error uploading file! filemanager sk Chyba počas odovzdávania súboru!
maximum size for uploads filemanager sk Maximálna veľkosť pre odovzdané súbory

View File

@ -403,3 +403,5 @@ writes a 'etemplates.inc.php' file (for application in name) in the setup-dir of
xml-file to import etemplate sl Datoteka XML za izvoz
xslt template etemplate sl Predloga XSLT
year etemplate sl Leto
error uploading file! filemanager sl Napaka pri prenosu datoteke!
maximum size for uploads filemanager sl Največja velikost za prenos

View File

@ -403,3 +403,5 @@ writes a 'etemplates.inc.php' file (for application in name) in the setup-dir of
xml-file to import etemplate zh 要导入的 XML-文件
xslt template etemplate zh XSLT 模板
year etemplate zh 年
error uploading file! filemanager zh 上传文件错误!
maximum size for uploads: %1 (php.ini: upload_max_filesize=%2, post_max_size=%3) filemanager zh 上传最大大小:%1 (php.ini: upload_max_filesize=%2, post_max_size=%3)

View File

@ -135,11 +135,6 @@ class filemanager_ui
if (!$content['nm']['filter']) $content['nm']['filter'] = '1';
}
}
// 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')))
{
$msg = lang('Error uploading file!')."\n".self::max_upload_size_message();
}
$content['nm']['msg'] = $msg;
if ($content['action'] || $content['nm']['rows'])
@ -247,7 +242,7 @@ class filemanager_ui
}
if ($upload_failure)
{
$content['nm']['msg'] .= ($upload_success ? "\n" : '').lang('Error uploading file!')."\n".self::max_upload_size_message();
$content['nm']['msg'] .= ($upload_success ? "\n" : '').lang('Error uploading file!')."\n".etemplate::max_upload_size_message();
}
break;
}
@ -264,7 +259,7 @@ class filemanager_ui
$clipboard_type=='copy'?lang('Copy'):lang('Move')).':</b><br />'.implode('<br />',$clipboard_files).'</p>' : '';
$content['linkpaste_tooltip'] = $clipboard_files ? '<p><b>'.lang('%1 the following files into current directory',
lang('link')).':</b><br />'.implode('<br />',$clipboard_files).'</p>' : '';
$content['upload_size'] = self::max_upload_size_message();
$content['upload_size'] = etemplate::max_upload_size_message();
//_debug_array($content);
$readonlys['button[linkpaste]'] = $readonlys['button[paste]'] = !$clipboard_files || !$dir_is_writable;
@ -347,47 +342,6 @@ class filemanager_ui
return $start;
}
/**
* 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').': '.egw_vfs::hsize($max_upload).
" (php.ini: upload_max_filesize=$upload_max_filesize, post_max_size=$post_max_size)";
}
/**
* Run a certain action with the selected file
*

View File

@ -63,7 +63,6 @@ enter the complete vfs path to specify a fast access link to a folder filemanage
enter the complete vfs path to specify your desired start folder. filemanager bg Въведете пълния VFS път, за да зададете желаната си стартова директория
error adding the acl! filemanager bg Грешка при добавяне на ACL!
error deleting the acl entry! filemanager bg Грешка при изтриване на ACL записа
error uploading file! filemanager bg Грешка при качване на файла!
executable filemanager bg Изпълним
extended access control list filemanager bg Разширен списък за контрол на достъпа (ACL)
extended acl filemanager bg Разширен ACL
@ -91,7 +90,6 @@ inherited filemanager bg Наследени
link %1: %2 filemanager bg Връзка %1: %2
location filemanager bg Местоположение
max folderlinks admin bg макс. връзки към директории
maximum size for uploads filemanager bg Максимален размер за качване
mime type filemanager bg MIME тип
modified filemanager bg променян на
modified between filemanager bg променян между

View File

@ -79,7 +79,6 @@ enter the complete vfs path to specify your desired start folder. filemanager cs
error adding the acl! filemanager cs Při přidávání ACL došlo k chybě!
error creating symlink to target %1! filemanager cs Chyba při vytváření symbolického odkazu na cíl %1!
error deleting the acl entry! filemanager cs Při mazání ACL záznamu došlo k chybě!
error uploading file! filemanager cs Chyba při uploadu souboru!
executable filemanager cs Spustitelný
extended access control list filemanager cs Rozšířený seznam přístupových oprávnění
extended acl filemanager cs Rozšířený ACL
@ -112,7 +111,6 @@ link target %1 not found! filemanager cs Odkaz na cíl %1 nebyl nalezen!
location filemanager cs Umístění
log out as superuser filemanager cs Odhlášení superuživatele
max folderlinks admin cs maximálně odkazů na složky
maximum size for uploads filemanager cs Maximální velikost pro uploady
mime type filemanager cs MIME typ
modified filemanager cs Změněno
modified between filemanager cs změněno mezi

View File

@ -79,7 +79,6 @@ enter the complete vfs path to specify your desired start folder. filemanager de
error adding the acl! filemanager de Fehler beim Hinzufügen des Zugriffsrechts!
error creating symlink to target %1! filemanager de Fehler beim Anlegen einer Verknüpfung zu %1!
error deleting the acl entry! filemanager de Fehler beim Löschen des Zugriffsrechts!
error uploading file! filemanager de Fehler beim Hochladen der Datei!
executable filemanager de Ausführbar
extended access control list filemanager de Erweiterte Zugriffsrechte
extended acl filemanager de Erweiterte ACL
@ -112,7 +111,6 @@ link target %1 not found! filemanager de Verküpfungsziel %1 nicht gefunden!
location filemanager de Ort
log out as superuser filemanager de Superuser abmelden
max folderlinks admin de maximale Anzahl von Links zu Verzeichnissen
maximum size for uploads filemanager de Maximale Größe beim Hochladen
mime type filemanager de MIME-Typ
modified filemanager de Verändert
modified between filemanager de verändert zwischen

View File

@ -79,7 +79,6 @@ enter the complete vfs path to specify your desired start folder. filemanager en
error adding the acl! filemanager en Error adding the ACL!
error creating symlink to target %1! filemanager en Error creating symlink to target %1!
error deleting the acl entry! filemanager en Error deleting the ACL entry!
error uploading file! filemanager en Error uploading file!
executable filemanager en Executable
extended access control list filemanager en Extended access control list
extended acl filemanager en Extended ACL
@ -112,7 +111,6 @@ link target %1 not found! filemanager en Link target %1 not found!
location filemanager en Location
log out as superuser filemanager en Log out as superuser
max folderlinks admin en max folderlinks
maximum size for uploads filemanager en Maximum size for uploads
mime type filemanager en mime type
modified filemanager en modified
modified between filemanager en modified between

View File

@ -76,7 +76,6 @@ enter the complete vfs path to specify your desired start folder. filemanager es
error adding the acl! filemanager es-es ¡Error al añadir la ACL!
error creating symlink to target %1! filemanager es-es ¡Error al crear el enlace simbólico al destino %1!
error deleting the acl entry! filemanager es-es ¡Error al borrar la entrada de la ACL!
error uploading file! filemanager es-es ¡Error al subir el fichero!
executable filemanager es-es Ejecutable
extended access control list filemanager es-es Listas de control de acceso extendidas
extended acl filemanager es-es ACL extendida
@ -108,7 +107,6 @@ link target %1 not found! filemanager es-es ¡No se ha encontrado el enlace de d
location filemanager es-es Ubicación
log out as superuser filemanager es-es Cerrar sesión como superusuario
max folderlinks admin es-es Número máximo de enlaces a carpetas
maximum size for uploads filemanager es-es Tamaño máximo para subida de ficheros
mime type filemanager es-es Tipo MIME
modified filemanager es-es Modificado
modified between filemanager es-es Modificado entre

View File

@ -79,7 +79,6 @@ enter the complete vfs path to specify your desired start folder. filemanager hu
error adding the acl! filemanager hu HIba a hozzáférés létrehozása során!
error creating symlink to target %1! filemanager hu Hiba a sylink létrehozása során %1 céhoz!
error deleting the acl entry! filemanager hu Hiba a hozzáférés törlése során!
error uploading file! filemanager hu HIba a file feltöltése során!
executable filemanager hu Végrehajtható
extended access control list filemanager hu Kiterjeszett hozzáférés korlátozás lista
extended acl filemanager hu Kiterjeszett hozzáférés korlátozás
@ -112,7 +111,6 @@ link target %1 not found! filemanager hu Link célpontja nem található (%1)!
location filemanager hu Hely
log out as superuser filemanager hu Rendszergazda kijelentkezés
max folderlinks admin hu maximális mappalink száma
maximum size for uploads filemanager hu Feltöltés maximális mérete
mime type filemanager hu MIME típus
modified filemanager hu Módosítva
modified between filemanager hu módosítva

View File

@ -66,7 +66,6 @@ enter the complete vfs path to specify a fast access link to a folder filemanage
enter the complete vfs path to specify your desired start folder. filemanager nl Vul het volledige VFS pad in om uw voorkeurs start folder te specificeren.
error adding the acl! filemanager nl Fout bij toevoegen van ACL!
error deleting the acl entry! filemanager nl Fout bij verwijderen van de ACL regel!
error uploading file! filemanager nl Fout bij uploaden van bestand!
executable filemanager nl Uitvoerbaar bestand
extended access control list filemanager nl Uitgebreide toegangscontrolelijst
extended acl filemanager nl Uitgebreide ACL
@ -96,7 +95,6 @@ link %1: %2 filemanager nl Link %1: %2
location filemanager nl Locatie
log out as superuser filemanager nl Uitloggen als supergebruiker
max folderlinks admin nl max folderlinks
maximum size for uploads filemanager nl Maximum grootte voor uploads
mime type filemanager nl MIME-type
modified filemanager nl Gewijzigd
modified between filemanager nl gewijzigd tussen

View File

@ -62,7 +62,6 @@ enter the complete vfs path to specify a fast access link to a folder filemanage
enter the complete vfs path to specify your desired start folder. filemanager pt-br Informe o caminho VFS completo para especificar sua pasta inicial desejada.
error adding the acl! filemanager pt-br Erro editanto a ACL!
error deleting the acl entry! filemanager pt-br Erro removendo o registro ACL!
error uploading file! filemanager pt-br Erro carregando arquivo!
executable filemanager pt-br Executável
extended access control list filemanager pt-br Lista de controle de acesso ampliada
extended acl filemanager pt-br ACL ampliada
@ -90,7 +89,6 @@ inherited filemanager pt-br Herdado
link %1: %2 filemanager pt-br Link %1: %2
location filemanager pt-br Localização
max folderlinks admin pt-br máximo de links para pastas
maximum size for uploads filemanager pt-br Tamanho máximo para uploads
mime type filemanager pt-br Tipo MIME
modified filemanager pt-br Modificado
modified between filemanager pt-br moficiado entre

View File

@ -79,7 +79,6 @@ enter the complete vfs path to specify your desired start folder. filemanager sk
error adding the acl! filemanager sk Chyba počas pridávania ACL!
error creating symlink to target %1! filemanager sk Chyba pri vytváraní symbolického odkazu na cieľ %1!
error deleting the acl entry! filemanager sk Chyba počas odstraňovania záznamu ACL!
error uploading file! filemanager sk Chyba počas odovzdávania súboru!
executable filemanager sk Spustiteľný
extended access control list filemanager sk Rozšírený zoznam prístupových oprávnení (ACL)
extended acl filemanager sk Rozšírený ACL
@ -112,7 +111,6 @@ link target %1 not found! filemanager sk Cieľ odkazu %1 sa nenašiel!
location filemanager sk Umiestnenie
log out as superuser filemanager sk Odhlásiť sa ako supervízor
max folderlinks admin sk max priečinkových odkazov
maximum size for uploads filemanager sk Maximálna veľkosť pre odovzdané súbory
mime type filemanager sk MIME typ
modified filemanager sk Zmenené
modified between filemanager sk Zmenené medzi

View File

@ -66,7 +66,6 @@ enter the complete vfs path to specify a fast access link to a folder filemanage
enter the complete vfs path to specify your desired start folder. filemanager sl Vnesite celotno pot VFS, da določite želeno začetno mapo.
error adding the acl! filemanager sl Napaka pri dodajanju ACL!
error deleting the acl entry! filemanager sl Napaka pri brisanju ACL!
error uploading file! filemanager sl Napaka pri prenosu datoteke!
executable filemanager sl Izvršilna
extended access control list filemanager sl Razširjen seznam kontrol dostopa
extended acl filemanager sl Razširjen ACL
@ -96,7 +95,6 @@ link %1: %2 filemanager sl Povezava %1: %2
location filemanager sl Lokacija
log out as superuser filemanager sl Odjavi se kot superuser
max folderlinks admin sl Največje število povezav do map
maximum size for uploads filemanager sl Največja velikost za prenos
mime type filemanager sl MIME tip
modified filemanager sl Spremenjeno
modified between filemanager sl Spremenjeno med

View File

@ -64,7 +64,6 @@ download filemanager zh 下载
edit filemanager zh 编辑
edit comments filemanager zh 编辑注释
error running command filemanager zh 命令执行出错
error uploading file! filemanager zh 上传文件错误!
execute filemanager zh 执行
failed to create directory filemanager zh 创建目录失败
failed to create directory! filemanager zh 创建目录失败!
@ -96,7 +95,6 @@ home filemanager zh 首页
id filemanager zh 编号
location filemanager zh 文件位置
locked filemanager zh 已锁定
maximum size for uploads: %1 (php.ini: upload_max_filesize=%2, post_max_size=%3) filemanager zh 上传最大大小:%1 (php.ini: upload_max_filesize=%2, post_max_size=%3)
mime type filemanager zh MIME类型
modified filemanager zh 修改日期
modified between filemanager zh 修改介于