diff --git a/adminer/include/functions.inc.php b/adminer/include/functions.inc.php index e1c2ffe1a..977d4869f 100644 --- a/adminer/include/functions.inc.php +++ b/adminer/include/functions.inc.php @@ -489,10 +489,18 @@ function get_file($key, $decompress = false) { if (!$file || $file["error"]) { return $file["error"]; } - return file_get_contents($decompress && ereg('\\.gz$', $file["name"]) ? "compress.zlib://$file[tmp_name]" + $return = file_get_contents($decompress && ereg('\\.gz$', $file["name"]) ? "compress.zlib://$file[tmp_name]" : ($decompress && ereg('\\.bz2$', $file["name"]) ? "compress.bzip2://$file[tmp_name]" : $file["tmp_name"] )); //! may not be reachable because of open_basedir + if ($decompress) { + if (function_exists("iconv") && ereg("^\xFE\xFF|^\xFF\xFE", $return, $regs)) { + $return = iconv("utf-16", "utf-8", $return); + } else { // not ternary operator to save memory + $return = ereg_replace("^\xEF\xBB\xBF", "", $return); // UTF-8 BOM + } + } + return $return; } /** Determine upload error diff --git a/adminer/select.inc.php b/adminer/select.inc.php index 4d2f9b477..d5af997cf 100644 --- a/adminer/select.inc.php +++ b/adminer/select.inc.php @@ -141,7 +141,7 @@ queries_redirect(remove_from_uri(), lang('%d item(s) have been affected.', $affected), $result); } } elseif (is_string($file = get_file("csv_file", true))) { - $file = preg_replace("~^\xEF\xBB\xBF~", '', $file); //! character set + //! character set $result = true; $cols = array_keys($fields); preg_match_all('~(?>"[^"]*"|[^"\\r\\n]+)+~', $file, $matches);