
Could you share an example file with me?
软件说明.txt
OK,this is the example file.
save problem
same problem
same problem
So I was finally able to display the file on my development machine with the following PHP code:
<?php
$encodeList = 'UTF-8, GB2312';
$file = file_get_contents('default.txt');
$encoding = mb_detect_encoding($file, $encodeList);
echo $encoding;
echo PHP_EOL;
echo mb_convert_encoding($file, 'UTF-8', $encoding);
However I'm still not sure how to properly solve this as showing GB2312 file is a general issue as we are using UTF-8 encoding all over the place. We could of course check the encoding on open and convert the file to UTF-8 but not sure if that is the desired behavior. Needs more research on how other platforms handle such files.
软件说明.txt
OK,this is the example file.
这个我弄好了,反正都是中国人会遇到这个问题,就用中文来回答吧,没测试所有文件类型,不知道这样做会不会引发其他问题。
修改文件路径:/服务器路径/nextcloud/apps/text/lib/Service/ApiService.php
第112行(line 112)修改为
return new FileDisplayResponse($file);
--->
$fileContents=$file->getContent();
$encoding = mb_detect_encoding($fileContents . 'a', 'UTF-8,GB2312, GBK, WINDOWS-1252, ISO-8859-15, ISO-8859-1, ASCII', true);
if ($encoding === '') {
$encoding = 'ISO-8859-15';
}
$fileContents = iconv($encoding, 'UTF-8', $fileContents);
$file->putContent($fileContents );
return new FileDisplayResponse($file);
Same issue for "windows-1250", see https://github.com/nextcloud/android/issues/6685#issuecomment-682554239 for an example file
Most helpful comment
这个我弄好了,反正都是中国人会遇到这个问题,就用中文来回答吧,没测试所有文件类型,不知道这样做会不会引发其他问题。
修改文件路径:/服务器路径/nextcloud/apps/text/lib/Service/ApiService.php
第112行(line 112)修改为
return new FileDisplayResponse($file);
--->
$fileContents=$file->getContent();
$encoding = mb_detect_encoding($fileContents . 'a', 'UTF-8,GB2312, GBK, WINDOWS-1252, ISO-8859-15, ISO-8859-1, ASCII', true);
if ($encoding === '') {
$encoding = 'ISO-8859-15';
}
$fileContents = iconv($encoding, 'UTF-8', $fileContents);
$file->putContent($fileContents );
return new FileDisplayResponse($file);