ZipArchive编码与日文文件名

时间:2015-07-06 03:10:03

标签: php

这就是我所做的

$zip = new \ZipArchive;
    $zip->open('file.zip', \ZipArchive::CREATE | \ZIPARCHIVE::OVERWRITE);
    foreach ($files as $file) { 
        $zip->addFile( "images/ルフィエール.jpeg");   
    }

但是在zip文件中它没有正确显示,但它显示如下:T¢+s¡s+Åpâ»péñpâ|pé+pâ.jpeg

请帮帮我!!!

1 个答案:

答案 0 :(得分:0)

尝试使用下面的代码,如果它不起作用尝试将zip中的文件名重命名为英语,然后查看它是否有效。如果是,那么问题不是来自ZipArchive或一般的压缩。

$zip = new \ZipArchive;
$zip->open('file.zip', \ZipArchive::CREATE | \ZIPARCHIVE::OVERWRITE);
foreach ($files as $file) { 
// Hopefully the filename below is dynamic and you're not actually adding the same file over and over
    $file = "images/ルフィエール.jpeg";
    $content = file_get_contents($file); 
    //if it is possible for you, I would change the filename to english below as well if this doesn't work
    $file_added = $zip->addFromString( pathinfo($file,PATHINFO_BASENAME) , $content);
}
$zip->close();