Jump to content

WireZipFile() and excluding files


flydev
 Share

Recommended Posts

I am working on a module and I need to exclude files/folders from a zip file created by wireZipFile() running on PW-3.0.38, without success.

In the following test code, for example I want to exclude the folder errors and his child files. It create the zip file but fail to exclude the folder even if $option['exclude'] is filed.

<?php namespace ProcessWire;

$foldertozip = $config->paths->templates;
$zipfile = $config->paths->templates.'test.zip';

$result = wireZipFile($zipfile, $foldertozip, array('exclude' => $config->paths->templates.'errors'));

$content = "";
foreach ($result['files'] as $file) {
    $content .= "Zipped $file<br>"; // the listing show the folder 'errors' and his child files
}

 

I also tested to modify the core file WireFileTools.php, function zip(), hardcoding the path to exclude, again without success...

 

already many hours trying to figure what the problem is >:(  Any idea guys ? thanks you.

Link to comment
Share on other sites

Thanks horst, yes but it wont work. For information the core function add and test the trailing slash : 

if(count($options['exclude']) && (in_array($name, $options['exclude']) || in_array("$name/", $options['exclude']))) continue;

 

Also I remember a detail, when I developed the profiles for Bootstrap and Foundation, I used ProcessExportProfile to export them, and this module try to exclude itself from the generated profile but it fail. So it look like an issue that is here since PW 2.7.

// code from ProcessExportProfile
[...]
$options = array(
	'dir' => $dir, 
	'exclude' => array("$dir/modules/ProcessExportProfile")
);
[...]

 

Edited by flydev
code
  • Like 1
Link to comment
Share on other sites

 @flydev: The code in your first post needs to assign an array to the exclude option:

$result = wireZipFile($zipfile, $foldertozip, array(
	'exclude' => array( $config->paths->templates.'errors')
));

From a quick glance at ProcessExportProfile, it looks like $dir is a relative path.

  • Like 2
Link to comment
Share on other sites

I thought that the core function was doing the job :

if(!is_array($options['exclude'])) $options['exclude'] = array($options['exclude']);

 

Anyway I tried to assign an array, it does not work. Really it drives me crazy lol

 

Edited by flydev
code
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...