php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60348 Unable to open new zipfile in mode OVERWRITE
Submitted: 2011-11-21 14:30 UTC Modified: 2020-03-21 07:11 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: dafish at soundtrack-board dot de Assigned:
Status: Not a bug Package: Zip Related
PHP Version: 5.3.8 OS: Linux Debian 2.6.32
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: dafish at soundtrack-board dot de
New email:
PHP Version: OS:

 

 [2011-11-21 14:30 UTC] dafish at soundtrack-board dot de
Description:
------------
I'm trying to open a zip file in mode OVERWRITE. I always end up getting error 
code 1,

Test script:
---------------
$this->archiveName = TEMP_DIR . '/archive_' . $this->tid . '_' . date('Ymd') . '.zip';

$errorCode = $this->zipArchive->open($this->archiveName, ZipArchive::CREATE);
if ((integer)$errorCode > 0)
{
    throw new RuntimeException('Unable to open archive ' . $this->archiveName . ' (Error: ' . $errorCode . ')');
}

if (empty($this->files))
{
    throw new RuntimeException('No files available to be added to the archive.');
}

foreach ($this->files as $filename => $filepath)
{
    $this->zipArchive->addFile($filepath, $filename);
}

if (!$this->zipArchive->close())
{
    throw new RuntimeException('An error occured while trying to write the archive.');
}

return $this->archiveName;


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-11-21 14:35 UTC] pajoye@php.net
can you create a self contained script? Use addFromString instead and drop 
everything not needed like exceptions and co, easier/faster for me to debug then.
 [2011-11-21 14:35 UTC] pajoye@php.net
-Status: Open +Status: Feedback
 [2011-11-21 14:42 UTC] dafish at soundtrack-board dot de
-Status: Feedback +Status: Open
 [2011-11-21 14:42 UTC] dafish at soundtrack-board dot de
Here is a little self contained script producing the same error:

$zip = new ZipArchive();

$archiveName = 'testtest.zip';
$error = $zip->open($archiveName, ZipArchive::OVERWRITE);
echo $error . PHP_EOL; // outputs '1'

$zip->addFromString('text.txt', 'Lorem Ipsum');

$zip->close();
 [2011-11-23 08:36 UTC] dafish at soundtrack-board dot de
After some more investigation along with an colleague I've found the source of 
the 
issue: I was trying to create the archive inside an directory which is symlinked 
to another directory. After adding realpath() to the archivename, the file could 
be successfully opened and stored.

I'm not sure if the error message was helpful at all and could be changed in the 
future.
 [2011-11-23 09:03 UTC] pajoye@php.net
hm, it supports symlink smoothly. Let me test again.
 [2011-11-23 09:03 UTC] pajoye@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: pajoye
 [2015-12-15 14:55 UTC] Vludko at gmail dot com
I have a same issue with PHP7.0 on ubuntu 15.10 but I dont have symlinks.

In OVERWRITE mode I get error code 1. But using mode CREATE zip file is successful created.
 [2015-12-18 12:55 UTC] Vludko at gmail dot com
Also php 7.0.1
 [2017-10-24 07:35 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: pajoye +Assigned To:
 [2020-03-21 07:11 UTC] remi@php.net
-Status: Open +Status: Not a bug
 [2020-03-21 07:11 UTC] remi@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

From documentation:
 ZipArchive::CREATE (integer):    Create the archive if it does not exist. 
 ZipArchive::OVERWRITE (integer): If archive exists, ignore its current contents.

So I only see expected behavior
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 07:01:27 2024 UTC