php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66713 Delete a file within a zip archive will not removed
Submitted: 2014-02-14 16:12 UTC Modified: 2015-04-26 04:22 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: prdatur at gmail dot com Assigned: cmb (profile)
Status: No Feedback Package: Zip Related
PHP Version: Irrelevant OS: Ubuntu 13.04
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: prdatur at gmail dot com
New email:
PHP Version: OS:

 

 [2014-02-14 16:12 UTC] prdatur at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/ziparchive.deleteindex
---

When opening a zip with ZipArchive and then deleting a file. The method returns true, getStatusString also returns no errors, but the file still exists within the archive.

Within the opened "Session" the file is correctly removed but it really the state is not written to the physical file so the removed file is not really removed.

Test script:
---------------
<?php
$zip_filename = '/var/www/www.zip';
$zip = new ZipArchive;
if ($zip->open($zip_filename) === TRUE) {
    for ($i = 0; $i < $zip->numFiles; $i++) {
        $filename = $zip->getNameIndex($i);
        echo $filename . "\n";
        if($filename === 'b.txt') {
            echo "Could be deleted by index? " . ($zip->deleteIndex($i) ? 'yes' : 'no') . "\n";
        }
    }          
    echo "Status string before delete by name: " . $zip->getStatusString() . "\n";
    echo "Could be deleted by name? " . ($zip->deleteName('b.txt') ? 'yes' : 'no') . "\n";
    echo "Status string after delete by name: " . $zip->getStatusString() . "\n";
    $zip->close();
    echo "Verify content of zip archive:\n";
    $zip2 = new ZipArchive;
    if ($zip2->open($zip_filename) === TRUE) {
        for ($i = 0; $i < $zip2->numFiles; $i++) {
            $filename = $zip2->getNameIndex($i);
            echo $filename . "\n";
        }
    }
    $zip2->close();
}
?>

Expected result:
----------------
Output: 
a.txt
b.txt
Could be deleted by index? yes
Status string before delete by name: No error
Could be deleted by name? no
Status string after delete by name: Entry has been deleted
Verify content of zip archive
a.txt

When changing to delete "a.txt" Output should be:
a.txt
Could be deleted by index? yes
b.txt
Status string before delete by name: No error
Could be deleted by name? no
Status string after delete by name: Entry has been deleted
Verify content of zip archive
b.txt

Actual result:
--------------
Output: 

a.txt
b.txt
Could be deleted by index? yes
Status string before delete by name: No error
Could be deleted by name? no
Status string after delete by name: Entry has been deleted
Verify content of zip archive
a.txt
b.txt

When changing to delete "a.txt" Output is:
a.txt
Could be deleted by index? yes
b.txt
Status string before delete by name: No error
Could be deleted by name? no
Status string after delete by name: Entry has been deleted
Verify content if zip archive:
a.txt
b.txt


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-04-16 01:22 UTC] cmb@php.net
-Package: zip +Package: Zip Related -Assigned To: +Assigned To: cmb
 [2015-04-16 12:30 UTC] cmb@php.net
-Status: Assigned +Status: Feedback
 [2015-04-16 12:30 UTC] cmb@php.net
I'm not able to reproduce the reported behavior with recent PHP
versions. Does the issue still persist? Which PHP version are you
using (please fill out the PHP version field)? Have you made sure
that the zip archive is not write protected?
 [2015-04-26 04:22 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 "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 12:01:30 2024 UTC