From 60ac6c5705764b61c0bd6f6eeb1497e3e497a79e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 14 Dec 2009 22:17:50 +0000 Subject: [PATCH] Fix: Add option MAIN_FILESYSTEM_ENCODING to solve pb of file encoding. --- htdocs/lib/functions.lib.php | 30 ++++++++++++++++++++++++------ htdocs/lib/security.lib.php | 6 +++--- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php index 9dc5922c8b6..7624dd0120e 100644 --- a/htdocs/lib/functions.lib.php +++ b/htdocs/lib/functions.lib.php @@ -1978,14 +1978,14 @@ function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite) return -1; } - // The file functions are ISO and data are stored in UTF8 in memory. - $src_file_iso=utf8_decode($src_file); - $file_name_iso=utf8_decode($file_name); + // The file functions must be in OS filesystem encoding. + $src_file_osencoded=dol_osencode($src_file); + $file_name_osencoded=dol_osencode($file_name); // Check if destination file already exists if (! $allowoverwrite) { - if (file_exists($file_name_iso)) + if (file_exists($file_name_osencoded)) { dol_syslog("Functions.lib::dol_move_uploaded_file File ".$file_name." already exists", LOG_WARNING); return -2; @@ -1993,10 +1993,10 @@ function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite) } // Move file - $return=move_uploaded_file($src_file_iso, $file_name_iso); + $return=move_uploaded_file($src_file_osencoded, $file_name_osencoded); if ($return) { - if (! empty($conf->global->MAIN_UMASK)) @chmod($file_name, octdec($conf->global->MAIN_UMASK)); + if (! empty($conf->global->MAIN_UMASK)) @chmod($file_name_osencoded, octdec($conf->global->MAIN_UMASK)); dol_syslog("Functions.lib::dol_move_uploaded_file Success to move ".$src_file." to ".$file_name." - Umask=".$conf->global->MAIN_UMASK, LOG_DEBUG); return 1; } @@ -3149,6 +3149,24 @@ function utf8_check($Str) } +/** + * \brief Return an UTF8 string encoded into OS filesystem encoding. This function is used to define + * value to pass to filesystem PHP functions. + * \param $str String to encode (UTF8) + * \return string Encoded string (UTF8, ISO-8859-1) + */ +function dol_osencode($str) +{ + $tmp=ini_get("unicode.filesystem_encoding"); // Disponible avec PHP 6.0 + if (empty($tmp) && ! empty($_SERVER["WINDIR"])) $tmp='iso-8859-1'; // By default for windows + if (empty($tmp)) $tmp='utf-8'; // By default for other + if (! empty($conf->global->MAIN_FILESYSTEM_ENCODING)) $tmp=$conf->global->MAIN_FILESYSTEM_ENCODING; + + if ($tmp == 'iso-8859-1') return utf8_decode($str); + return $str; +} + + /** * \brief Return an id from a Code. Store Code-Id in a cache. * \param db Database handler diff --git a/htdocs/lib/security.lib.php b/htdocs/lib/security.lib.php index d1d3fa262f1..6c215029ce9 100644 --- a/htdocs/lib/security.lib.php +++ b/htdocs/lib/security.lib.php @@ -466,7 +466,7 @@ function dol_encode($chain) $output_tab[$i] = chr(ord(substr($chain,$i,1))+17); } - $string_coded = base64_encode(implode ("",$output_tab)); + $string_coded = base64_encode(implode("",$output_tab)); return $string_coded; } @@ -484,7 +484,7 @@ function dol_decode($chain) $output_tab[$i] = chr(ord(substr($chain,$i,1))-17); } - $string_decoded = implode ("",$output_tab); + $string_decoded = implode("",$output_tab); return $string_decoded; } @@ -508,7 +508,7 @@ function dol_avscan_file($file) $maxfilesize = 10485760; // archived files larger than this value (in bytes) will not be scanned cl_setlimits($maxreclevel, $maxfiles, $maxratio, $archivememlim, $maxfilesize); - $malware = cl_scanfile($file); + $malware = cl_scanfile(dol_osencode($file)); } return $malware;