|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-12-31 20:27 UTC] killerbg at gmail dot com
Description:
------------
On Windows XP Professional Service Pack 3 with Apache 2.2.11 and PHP 5.2.8 - PHP 5.2.9 loaded as dynamic module when creating archive and adding files and/or folders the ouput is incorrect and the file gets corrupted. Even trying to open it again with the script results error code 19.
Reproduce code:
---------------
$file = tempnam("/tmp/", "php");
$zip = new ZipArchive();
if (($zip->open($file, ZipArchive::OVERWRITE)) === TRUE)
{
$zip->addEmptyDir("Directory");
$zip->addFile("File");
$zip->close();
}
Expected result:
----------------
Correctly created zip archive file with unique name located in the temporaly directory.
Actual result:
--------------
Only the firsts few added files visible but corrupted acording to the crc32 record.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 01:00:01 2025 UTC |
It works just fine here (in apache2 sapi, iis, fcgi and cli). Can you try the following script please? I suspect some other errors happening and they are not displayed. Be sure to have display_errors activated. By the way, in the latest releases there are "addFromPattern"/"Glob" functions which let you add recursively something like "*.jpeg" :) <?php $path = 'C:\yourpath\\'; $count = 0; function archive($path, $local) { global $zip, $count; if ($handle = opendir($path)) { while (($file = readdir($handle)) !== false) { if (($file != ".") && ($file != "..")) { echo "$file\n"; var_dump($local, $file, $path); if (is_dir($path . $file)) { $zip->addEmptyDir($local . $file . "/"); archive($path . $file . "/", $local . $file . "/"); } elseif (is_file($path . $file)) { if ($count > 128) { $zip->close(); $zip->open($GLOBALS["file"]); $count = 0; } $zip->addFile($path . $file, $local . $file); $count++; } } } closedir($handle); } echo "count: $count\n"; } $file = 't.zip'; $zip = new ZipArchive(); if (($zip->open($file, ZipArchive::CREATE)) === TRUE) { archive($path, null); $zip->close(); } echo "done\n";