|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51857 deleteName() for directories returns True on non-success
Submitted: 2010-05-19 09:43 UTC Modified: 2013-02-18 00:34 UTC
Avg. Score:4.2 ± 0.8
Reproduced:4 of 4 (100.0%)
Same Version:2 (50.0%)
Same OS:1 (25.0%)
From: nuabaranda at web dot de Assigned: pajoye (profile)
Status: No Feedback Package: Zip Related
PHP Version: 5.3.3-dev OS: Linux 2.6.27
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: nuabaranda at web dot de
New email:
PHP Version: OS:


 [2010-05-19 09:43 UTC] nuabaranda at web dot de
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('', ZipArchive::CREATE) ) {
  if( ! $zip->deleteName('folder/') ) {
    echo 'Should end up here if folder not deletable';

Expected result:
Should echo.

Actual result:
Will not echo.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-05-21 19:41 UTC]
-Status: Open +Status: Verified -PHP Version: 5.2.13 +PHP Version: 5.3.3-dev
 [2010-05-21 19:41 UTC]
And for good measure:

define ('FILEPATH_ZIPFILE', '/tmp/');

/* Create the Zip file */
$zip = new ZipArchive;

	$zip->addFromString('foo.txt', 'foo');
	$zip->addFromString('bar.txt', 'bar');
	$zip->addFromString('FullDirectory/baz.txt', 'baz');

/* 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/');


/* 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;


    array('r1' => $r1, 'r2' => $r2, 'r3' => $r3, 'r4' => $r4)


File count: 3
Status: 0
Index: 0 foo.txt
Index: 1 bar.txt
Index: 2 FullDirectory/baz.txt
array(4) {
 [2010-05-22 00:16 UTC]
-Assigned To: +Assigned To: pajoye
 [2010-09-14 15:19 UTC]
-Status: Verified +Status: Feedback
 [2010-09-14 15:19 UTC]
Please try using this snapshot:
For Windows:

I can't reproduce the problem, can you try again pls?
 [2012-05-24 03:14 UTC] maxspeed40k at gmail dot com
reproduce the problem
PHP Version: 5.4.3
OS: windows 7
 [2013-02-18 00:34 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Jul 02 07:01:25 2020 UTC