|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-11-08 13:07 UTC] luc_azer at yahoo dot fr
Description:
------------
I want to add an image files (logo.gif) to a newly created and not yet existing zip-archive by using the method 'ZipArchive::addFile'.
WinRAR 3.61 reports Diagnostic messages:
CRC failed in logo.gif
The file is corrupt
Winzip 9.0: invalid compressed data to inflate.
The result come from a modify version of the create.php example
Reproduce code:
---------------
<?php
error_reporting(E_ALL);
if (!extension_loaded('zip')) {
dl('zip.so');
}
$thisdir = dirname(__FILE__);
unlink("./test112.zip");
$zip = new ZipArchive();
$filename = "./test112.zip";
if (!$zip->open($filename, ZIPARCHIVE::CREATE)) {
exit("cannot open <$filename>\n");
} else {
echo "file <$filename> OK\n";
}
$zip->addFromString("testfilephp.txt" . time(), "#1 This is a test string added as testfilephp.txt.\n");
$zip->addFromString("testfilephp2.txt" . time(), "#2 This is a test string added as testfilephp2.txt.\n");
$zip->addFile($thisdir . "/logo.gif","/logo.gif");
echo "numfiles: " . $zip->numFiles . "\n";
echo "status:" . $zip->status . "\n";
$zip->close();
unset($zip);
?>
Expected result:
----------------
I expected newly created zip-archive with the readable image inside.
Actual result:
--------------
Impossible to read the image inside the zip file.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 03:00:02 2025 UTC |
Can you try this script? and give me the result? <?php error_reporting(E_ALL); unlink("./a.zip"); $zip = new ZipArchive(); $filename = "./a.zip"; if (!$zip->open($filename, ZIPARCHIVE::OVERWRITE)) { exit("cannot open <$filename>\n"); } else { echo "file <$filename> OK\n"; } $zip->addFromString("ma.txt", "0123456789"); var_dump($zip->close()); var_dump($zip);The result of your script test is : file <./a.zip> OK bool(true) object(ZipArchive)#1 (5) { ["status"]=> int(0) ["statusSys"]=> int(0) ["numFiles"]=> int(0) ["filename"]=> string(0) "" ["comment"]=> string(0) "" } Winzip 9.0 alert message when opening the archive: Cannot open file:It does not appear to be a valid archive