0

I have zip file which contains photo with filename "test1ąąążżżźźźźććć.jpg", as you can see it contains only special characters from Polish language. When I'm trying to extract it with PHP code it returns filename "test1ÑÑÑ╛╛╛½½½½ååå.jpg". But when I'm extracting filenames with special characters from more than one language like "test2óôśšźżžøùú.jpg" (in this filename Polish char is included too) it's working good with no problems. So it looks like in most cases PHP zip extracting crashes only with Polish language filenames.

Here is the code that I used to extract zip files:

function extractZip($file, $path=NULL) {
    if($path == NULL)
        $path = pathinfo(realpath($file), PATHINFO_DIRNAME);

    $zip = new ZipArchive;
    $res = $zip->open($file);
    if ($res === TRUE) {
        $zip->extractTo($path);
        $zip->close();
        echo "Ok,  $file extracted to $path";
    } else {
        echo "Error";
    }
}

extractZip('test.zip');

I'm sure that is not problem with my system or zip file. When I extracted zips by regular windows explorer not by script everything worked good. Please help, I tried a lot of methods and searched through the web and I have no idea how to solve it.

  • I guess it's a bug of ziparchive, to look for /report at https://bugs.php.net/report.php?bug_type=Documentation+problem&manpage=class.ziparchive and don't see what we could do about it here... – B. Go Jan 14 '20 at 22:54
  • It's not a bug, it's a character set mismatch. Educated guess: Your zip file is probably encoded in [ISO-8859-2](https://en.wikipedia.org/wiki/ISO/IEC_8859-2#Code_page_layout), and you're viewing it in something set to [CP852](https://en.wikipedia.org/wiki/Code_page_852). Either change your display encoding to 8859-2, or convert everything to UTF-8. https://stackoverflow.com/questions/279170/utf-8-all-the-way-through – Sammitch Jan 15 '20 at 01:41

0 Answers0