Cyrillic problems when creating archives with php zip. In particular, a database dump in utf-8 encoding is added to the archive. At the exit from the archive encoding breaks.

Sample code.

$archiveName = date('YmdHi') . '-' . APP::$conf['location'][1] . '.zip'; $zip = new ZipArchive; $zip->open($archiveName, ZIPARCHIVE::CREATE); // create recursive directory iterator $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(ROOT), RecursiveIteratorIterator::LEAVES_ONLY); foreach ($files as $name => $file) { $filePath = $file->getRealPath(); $localPath = explode(ROOT, $filePath); if ((strpos($filePath, ROOT . '/logs') !== false) || (strpos($filePath, ROOT . '/tmp') !== false)) { continue; } else { if (is_file($filePath)) { // echo mb_substr($localPath[1], 1)."<br>"; $zip->addFile(mb_substr($localPath[1],1)); } } } $zip->close(); header('Content-Type: application/zip; charset=utf-8'); header('Content-Length: ' . filesize($archiveName)); header('Content-Disposition: attachment; filename="' . $archiveName.'"'); readfile($archiveName); // unlink($archiveName); rmdir($backupDir); exit; 
  • Can the file name need to escape? - nick_n_a
  • Is the file name encoding or encoding inside the file broken? - Dmitry Kozlov
  • This is a known bug. bugs.php.net/bug.php?id=53948 - rjhdby

0