php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70103 ZipArchive::addGlob ignores remove_all_path option
Submitted: 2015-07-20 13:21 UTC Modified: 2017-01-06 14:54 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:1 of 2 (50.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: cronoklee at hotmail dot com Assigned: cmb (profile)
Status: Closed Package: zip (PECL)
PHP Version: 5.6.11 OS: *
Private report: No CVE-ID: None
 [2015-07-20 13:21 UTC] cronoklee at hotmail dot com
Description:
------------
---
From manual page: http://www.php.net/ziparchive.addglob
---

After creating a zip archive using addGlob, the zip appears empty in Windows explorer due to the directory path being prepended to the files.

Test script:
---------------
$dir = '../temp';
$zip = new ZipArchive();
$zip -> open('../test.zip', ZipArchive::OVERWRITE);
$zip -> addGlob( $dir.'/*.txt', GLOB_NOSORT, array('remove_all_path' => TRUE) );
$zip -> close();

Expected result:
----------------
The 'remove_all_path'=>TRUE flag should place the files in the root directory of the zip archive.

NOTE: a workaround is to add a space before each file path name using the 'add_path' flag like so:
array('add_path' => ' ','remove_all_path' => TRUE)

Actual result:
--------------
Despite the 'remove_all_path'=>TRUE flag, the zipped files DO contain the '../temp' prefix, meaning that they cannot be read in Windows explorer.

Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-07-20 14:33 UTC] cmb@php.net
-Status: Open +Status: Analyzed
 [2015-07-20 14:33 UTC] cmb@php.net
I can confirm this issue. It seems that the remove_all_path option
is properly processed and file_stripped holds the filename without
the path[1], but if no add_path option is given, file_stipped is
simply ignored when constructing the entry_name[2].

[1] <https://github.com/php/php-src/blob/php-5.6.11/ext/zip/php_zip.c#L1779-L1789>
[2] <https://github.com/php/php-src/blob/php-5.6.11/ext/zip/php_zip.c#L1779-L1789>
 [2015-07-20 15:17 UTC] cmb@php.net
-Summary: ZipArchive -> addGlob creating empty directories in for Windows +Summary: ZipArchive::addGlob ignores remove_all_path option -Operating System: CentOS 6 +Operating System: * -PHP Version: 5.5.27 +PHP Version: 5.6.11
 [2017-01-06 05:42 UTC] krakjoe@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=php-src.git;a=commit;h=c36ce04dd36c5d90363f843bc7fea1bb753cef93
Log: Fix #70103: ZipArchive::addGlob ignores remove_all_path option
 [2017-01-06 05:42 UTC] krakjoe@php.net
-Status: Analyzed +Status: Closed
 [2017-01-06 14:51 UTC] cmb@php.net
Automatic comment on behalf of mhagstrand@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=ad08aa39561eb6aa3d03b2be06ed3894dbb2892c
Log: Fix #70103: Fix bug 70103 when ZTS is enabled
 [2017-01-06 14:54 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 09:01:32 2024 UTC