I am using jqueryFileTree to show a directory listing on the server with download links to the files in the directory. Recently I\'ve run into an issue with files which cont
My best guess is that the filename itself isn't using UTF-8. Or at least scandir()
isn't picking it up like that.
Maybe mb_detect_encoding()
can shed some light?
var_dump(mb_detect_encoding($filename));
If not, try to guess the encoding (CP1252 or ISO-8859-1 would be my first guess) and convert it to UTF-8, see if the output is valid:
var_dump(mb_convert_encoding($filename, 'UTF-8', 'Windows-1252'));
var_dump(mb_convert_encoding($filename, 'UTF-8', 'ISO-8859-1'));
var_dump(mb_convert_encoding($filename, 'UTF-8', 'ISO-8859-15'));
Or using iconv()
:
var_dump(iconv('WINDOWS-1252', 'UTF-8', $filename));
var_dump(iconv('ISO-8859-1', 'UTF-8', $filename));
var_dump(iconv('ISO-8859-15', 'UTF-8', $filename));
Then when you've figured out which encoding is actually used, your code should look somewhat like this (assuming CP1252):
$filename = htmlentities(mb_convert_encoding($filename, 'UTF-8', 'Windows-1252'), ENT_QUOTES, 'UTF-8');