flydev Posted November 2, 2016 Share Posted November 2, 2016 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 More sharing options...
horst Posted November 2, 2016 Share Posted November 2, 2016 just a thought: have you tested it with a trailing slash? array('exclude' => $config->paths->templates.'errors/') Link to comment Share on other sites More sharing options...
flydev Posted November 2, 2016 Author Share Posted November 2, 2016 (edited) 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 November 2, 2016 by flydev code 1 Link to comment Share on other sites More sharing options...
BitPoet Posted November 2, 2016 Share Posted November 2, 2016 @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. 2 Link to comment Share on other sites More sharing options...
flydev Posted November 2, 2016 Author Share Posted November 2, 2016 (edited) 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 November 2, 2016 by flydev code Link to comment Share on other sites More sharing options...
BitPoet Posted November 2, 2016 Share Posted November 2, 2016 Ah, should have looked more closely. Try this: $result = wireZipFile($zipfile, $foldertozip, array( 'exclude' => array( basename($config->paths->templates) . '/errors') )); 2 Link to comment Share on other sites More sharing options...
flydev Posted November 2, 2016 Author Share Posted November 2, 2016 woohoo thanks you! how I missed that - its working 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now