1

I'm having trouble while adding files to a zip when the file name has special characters like "áéãô". The code is really simple and everything is working. Here it is:

$newZip = new ZipArchive();
$newFile = DIR."/".$repo_name.".zip";
$open_newZip = $newZip->open($newFile, ZIPARCHIVE::CREATE);

        if($open_newZip === TRUE){

            sort($arquivos);    

            foreach( $arquivos as $arquivo ){
                //I tried this but it doesn't make any difference at all
                header('Content-Type: text/html; charset=utf-8'); 

                $newZip_baseName = pathinfo($arquivo, PATHINFO_BASENAME);
                $newZip->addFile($arquivo,  $newZip_baseName);
        } else {
            echo 'Error openning the new file. Error: '. $open;
        }

For example: the file is "1Nandõ Reis - N.mp3" and in the zip file it appears like "1Nand├╡ Reis - N.mp3". When unziped (it's correct? hahaha) the file is still "1Nand├╡ Reis - N.mp3".

I tried this: Getting UTF-8 filenames to work with PHP ZipArchive (which gives me a different result - the file is saved like "1Nandї Reis - N.mp3"- but doesn't solve my problem)

And this: http://grokbase.com/t/php/php-bugs/1127mqqbd8/php-bug-bug-53948-new-zip-archive-utf-8-filenames-problem

And the oficial bug report: https://bugs.php.net/bug.php?id=53948

Most of the links above indicates this: PHP ZipArchive non-English filenames return funky filenames within archive which I also tried without any success. I'm afraid that all this solutions are for windows only. Someone have a workaround for Linux?

Community
  • 1
  • 1

1 Answers1

0

It is the usual «on my computer I can save a file with that name, so it's your fault» syndrome. Never seen a Justin Bieber's MP3 with a lot of ♥ in the filename "just because it's possible"?

For Linux I found the command convmv which sounds promising — see http://linux.die.net/man/1/convmv

I think you can exec() it from PHP, too.

Marco Bernardini
  • 695
  • 6
  • 17
  • Thanks! This was not the exact answer, but as you gave me the way to solve my problem, I'm marking as accepted. Instead of ZipArchive, I used `exec(zip -r -j directory filename.zip)` -r to be recursive and -j to avoid the original path and save the files on the root of the zip... and it works like a charm! Just to be sure: does this exec() funtion leads to any server vulnerability? – mariannactx Apr 17 '15 at 00:53
  • IIRC it's possible to "sandbox" the executable programs, but I don't remember exactly how. Of course you can't exec everything in /usr/bin! – Marco Bernardini Apr 17 '15 at 01:18