diff --git a/actions/archive.action.inc b/actions/archive.action.inc new file mode 100644 index 0000000..4731590 --- /dev/null +++ b/actions/archive.action.inc @@ -0,0 +1,42 @@ + FALSE, so that it can handle a + * larger number of files. + */ + +function views_bulk_operations_archive_action_info() { + return array('views_bulk_operations_archive_action' => array( + 'type' => 'file', + 'label' => t('Download archive of selected files'), + 'configurable' => FALSE, + 'aggregate' => TRUE, + )); +} + +function views_bulk_operations_archive_action($files, $context) { + // Create zip file. + $zipfile = tempnam(file_directory_temp(), 'zip'); + $zip = new ZipArchive(); + if (!$zip->open($zipfile, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE)) { + return; + } + foreach ($files as $file) { + $zip->addFile(drupal_realpath($file->uri),$file->filename); + } + $zip->close(); + + // Download zip file. + $zipname = 'files-'. date('Ymd-His') .'.zip'; + header('Content-Type: application/zip'); + header('Content-Disposition: attachment; filename='. $zipname); + header('Content-Transfer-Encoding: binary'); + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + header('Pragma: public'); + header('Expires: 0'); + header('Content-Length: '. filesize($zipfile)); + readfile($zipfile); + unlink($zipfile); + exit; +} diff --git a/views_bulk_operations.module b/views_bulk_operations.module index be9c24a..2512e0a 100644 --- a/views_bulk_operations.module +++ b/views_bulk_operations.module @@ -43,6 +43,7 @@ function views_bulk_operations_load_action_includes() { // caching the result has its cost). $path = drupal_get_path('module', 'views_bulk_operations') . '/actions/'; $files = array( + 'archive.action.inc', 'argument_selector.action.inc', 'delete.action.inc', 'script.action.inc',