I have a file that I want to add to a Zip with PHP, which is encoded in UTF-8. Here is the filename: 'µ漢字ääÖÅ.txt'.
Now, to get this file even to save to the filesystem I had to do this:
$filename = "µ漢字ääÖÅ.txt";
$codepage = 'Windows-' . trim(strstr(setlocale(LC_CTYPE, 0), '.'), '.');
$encoded_filename = iconv('UTF-8', $codepage.'//IGNORE', $filename);
file_put_contents($encoded_filename, "text");
Now when I want to add the file to the ziparchive I use the following code:
$zip = new \ZipArchive();
$zip->open('test.zip', \ZIPARCHIVE::CREATE);
$zip->addFile($encoded_filename, $encoded_filename);
$zip->close();
Which results in a zip file containing the file name 'ÁõõÍ+.txt'. How do I get it to save correctly?