I have a task to upload a txt file to the FTP server using League\Flysystem
with UTF-8
Code which is responsible for that is looking like this:
...
use League\Flysystem\FilesystemInterface;
final class UploadToFTPHandler implements CommandHandlerInterface
{
private FilesystemInterface $filesystem;
public function __construct(FilesystemInterface $ftpFilesystem)
{
$this->filesystem = $ftpFilesystem;
}
public function __invoke(UploadToFTP $command): void
{
$fileContents = 'którzy uczestniczyć w procesie o stary zamek, niegdyś własność';
$fileContents = mb_convert_encoding($fileContents, 'UTF-8');
$this->filesystem->write(
sprintf('%s.txt', uniqid()),
$fileContents,
['mimetype' => 'text/plain; charset=utf-8']
);
}
}
After uploading this file, when I open it on my server, it looks like this:
którzy uczestniczyć w procesie o stary zamek, niegdyĹ› wĹ‚asność
As you can see, there is no utf-8 encoding despite that I have set ['mimetype' => 'text/plain; charset=utf-8']
and mb_convert_encoding($fileContents, 'UTF-8')
What I am doing wrong to achieve correct UTF-8
encoding?
Implementation of this method $this->filesystem->write
is here