php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50141 folders inside a zip archive are not displayed
Submitted: 2009-11-10 19:26 UTC Modified: 2009-11-11 17:40 UTC
From: samantha86 at web dot de Assigned:
Status: Not a bug Package: Zip Related
PHP Version: 5.3.0 OS: windows (xp and 7)
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: samantha86 at web dot de
New email:
PHP Version: OS:

 

 [2009-11-10 19:26 UTC] samantha86 at web dot de
Description:
------------
hi,

i have a problem with files generated/altered via the ziparchive class.
my problem is the same as Bug #39714, but i have been using php 5.3.0 instead of 5.2.x

i use to use ubuntu linux and i have NO problem there with extracting the zip files. it does not matter on what server the zip files are generated, windows or linux, it depends on the client where i try to open one of these zip files.

the code for the zipfile generation looks like this:



Reproduce code:
---------------
<?php
class Zipper extends ZipArchive {

public function addDir($path, $newname) {
	$nodes = glob($path.DIRECTORY_SEPARATOR."*");
	if (!empty($nodes)) {
		foreach ($nodes as $node) {
			//exclude temporary files
			if (substr($node,-1)!="~") {
		                $newnode=substr($node,strlen($path)+1);
				$newnode=$newname.DIRECTORY_SEPARATOR.$newnode;
				if (is_dir($node)) {
					$this->addDir($node,$newnode);
				} else if (is_file($node))  {
					$this->addFile($node,$newnode);
				}
			}
		}
	}
}

}
?>

Expected result:
----------------
i'd like to receive a zipfile where i can see the files, but also the directories wit the included files that are generated in a deeper recursion of the function

Actual result:
--------------
under windows i only see the files that are in the root of the zip archive, under ubuntu linux everything is ok.


thank you in advance for sacrificing your time

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-10 19:31 UTC] pajoye@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.


 [2009-11-10 20:03 UTC] samantha86 at web dot de
here is some example code, an already generated zip file can be downloaded at my demoserver http://steffisgarten.bplaced.net/chillyCMS/admin/tools.site.php?tool=backup
username: admin, pw: demo
maybe this can save you some time.

<?php
class Zipper extends ZipArchive {

public function addDir($path, $newname) {
	$nodes = glob($path.DIRECTORY_SEPARATOR."*");
	if (!empty($nodes)) {
		foreach ($nodes as $node) {
			//exclude temporary files
			if (substr($node,-1)!="~") {
		                $newnode=substr($node,strlen($path)+1);
				$newnode=$newname.DIRECTORY_SEPARATOR.$newnode;
				if (is_dir($node)) {
					$this->addDir($node,$newnode);
				} else if (is_file($node))  {
					$this->addFile($node,$newnode);
				}
			}
		}
	}
}

}

$zip=new Zipper();
if ($zip->open($file_dest, ZIPARCHIVE::CREATE)) {
	$zip->addDir(PATH."/example", "/example");
} else {
	echo "error";
}
?>
 [2009-11-10 23:47 UTC] fa@php.net
If I open your zip file with 7-ZIP instead of the integrated windows zip tool, there's a folder with a weird name.

Might be just a blank space, might be a null byte.
But in that folder I see many folders:
admin / backup / core / installation / and some more

Can you please verify that your generated subfolder name is not just incorrectly set?
 [2009-11-11 09:38 UTC] samantha86 at web dot de
yes, this folder includes some other folders, which can be seen when using a linux machine.

the structure should look like this:

myzipfile.zip
   |_ /admin
   |_ /core
   |_ ...some othe folders...
   |_ config.php
   |_ ...some other files in the root of the zipfile...

the code i use to add the directories/files it looks exactly like this:

<?php
...
//for the directories:
$zip->addDir(PATH."/admin", "/admin");
$zip->addDir(PATH."/core", "/core");"/languages");
...
for the files:
$zip->addFile(PATH."/backup/files/config.php", "config.php");
$zip->addFile(PATH."/backup/files/index.php", "index.php");
...
?>
 [2009-11-11 09:40 UTC] samantha86 at web dot de
oh sorry that piece: "/languages");
was too much, it is not in my orignal code. just a copy and paste error.
 [2009-11-11 12:11 UTC] fa@php.net
Addendum:
if I change
  $zip->addDir(PATH."/example", "/example");
to
  $zip->addDir(PATH."/example", "example");
I can avoid this in 5.2.6 (debian php), 5.3.0 and 5.3.1RC3
and get:
example/x.ini
 [2009-11-11 15:31 UTC] samantha86 at web dot de
now i feel pretty sheepish...

  ,---@>
   W-W'

thank you for your support, it works under ubuntu/xp and 7 now!
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Feb 05 09:01:30 2025 UTC