There exists a bug in PHP which mangles filenames on uploads - see see http://bugs.php.net/bug.php?id=47096 . Therefore I am using a function to convert the filename to proper UTF8.
Heart of the function is:
if ( 'WIN' == substr( PHP_OS, 0, 3 ) ) {
$codepage = 'Windows-' . trim( strstr( setlocale( LC_CTYPE, 0 ), '.' ), '.' );
if ( function_exists( 'iconv' ) ) {
$filename = iconv( 'UTF-8', $codepage, $filename );
} elseif ( function_exists( 'mb_convert_encoding' ) ) {
$filename = mb_convert_encoding( $filename, 'UTF-8', $codepage );
}
}
This worked fine with older PHP versions (<5.2). However with recent PHP versions the command
setlocale( LC_CTYPE, 0 )
returns 'C' - which is obviously not a Windows code page and so the conversion fails.
Is there a reliable or alternative way to retrieve the current Windows code page in PHP?