|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-05-19 09:43 UTC] nuabaranda at web dot de
Description:
------------
When trying to delete a non-empty directory in a ZIP file with deleteName() the function will return True and not delete the directory if it is not empty. Expectation would be to return False if the directory can not be deleted.
Also the directory handling should be better documentated (usage of trailing slashes, examples).
Test script:
---------------
$zip = new ZipArchive;
if( $zip->open('archive.zip', ZipArchive::CREATE) ) {
$zip->addEmptyDir('folder');
$zip->addFile('folder/file.txt');
if( ! $zip->deleteName('folder/') ) {
echo 'Should end up here if folder not deletable';
}
}
$zip->close();
Expected result:
----------------
Should echo.
Actual result:
--------------
Will not echo.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 05:00:01 2025 UTC |
And for good measure: <?php define ('FILEPATH_ZIPFILE', '/tmp/test.zip'); /* Create the Zip file */ $zip = new ZipArchive; if ($zip->open(FILEPATH_ZIPFILE, ZIPARCHIVE::CREATE) === TRUE) { $zip->addFromString('foo.txt', 'foo'); $zip->addFromString('bar.txt', 'bar'); $zip->addEmptyDir('EmptyDirectory'); $zip->addEmptyDir('FullDirectory'); $zip->addFromString('FullDirectory/baz.txt', 'baz'); $zip->close(); } /* Mess with the Zip file */ $zip = new ZipArchive; if ($zip->open(FILEPATH_ZIPFILE) === TRUE) { /* Fails to delete */ $r1 = $zip->deleteName('EmptyDirectory'); /* Successful delete (note the appended '/' */ $r2 = $zip->deleteName('EmptyDirectory/'); /* Fails to delete */ $r3 = $zip->deleteName('FullDirectory'); /* Fails to delete, although returns true */ $r4 = $zip->deleteName('FullDirectory/'); $zip->close(); } /* Display the Zip file contents */ $zip = new ZipArchive; if ($zip->open(FILEPATH_ZIPFILE) === TRUE) { echo 'File count: ', $zip->numFiles, PHP_EOL; echo 'Status: ', $zip->status, PHP_EOL; for ($i = 0; $i < $zip->numFiles; $i++) { $stat = $zip->statIndex($i); echo 'Index: ', $i, ' ', $stat['name'], PHP_EOL; } $zip->close(); } var_dump( array('r1' => $r1, 'r2' => $r2, 'r3' => $r3, 'r4' => $r4) ); Returns: File count: 3 Status: 0 Index: 0 foo.txt Index: 1 bar.txt Index: 2 FullDirectory/baz.txt array(4) { ["r1"]=> bool(false) ["r2"]=> bool(true) ["r3"]=> bool(false) ["r4"]=> bool(true) }