From 7c2e5898630b076faf3c64ccc364fa37be2de9e9 Mon Sep 17 00:00:00 2001 From: Ludovic Pouzenc Date: Wed, 6 Nov 2013 20:34:17 +0100 Subject: Gestion des erreurs dans add.php coté php. Pas de feedback user encore. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/admin/utils.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'code/admin/utils.php') diff --git a/code/admin/utils.php b/code/admin/utils.php index 4db2d2d..30d3788 100644 --- a/code/admin/utils.php +++ b/code/admin/utils.php @@ -4,6 +4,11 @@ define('RE_LANG_IDENT_CLEANER', '/[^a-zA-Z\/\_-]+/'); define('RE_RELPATH_CLEANER', '/[^a-zA-Z0-9_\/-]+/'); // Never put \. in this regex + define('E_INVALID_ACTION', -1); + define('E_INVALID_PATH', -2); + define('E_INVALID_NAME', -3); + define('E_SYSTEM_ERROR', -4); + function sanitize($arg_array, $arg_key, $replace_chars_re, $default_value) { //FIXME : should check string type and strlen ! if ( ! array_key_exists($arg_key, $arg_array) ) return $default_value; @@ -140,14 +145,15 @@ echo "\n"; } + // TODO : choose between unix convention (0 is fine, else is error) and PHP one (FALSE is error, else is okay) function safe_put_file($path, $content) { //FIXME : if exists, then mktemp, put in it then rm and mv. Right preservation problems ? - $res=FALSE; + $res=-1; if ($handle = fopen($path, 'w')) { $res = fwrite($handle, $content); fclose($handle); } - return $res; + return ($res===strlen($content))?0:E_SYSTEM_ERROR; } function _write_ini_file_r(&$content, $assoc_arr, $has_sections) -- cgit v1.2.3