Module 从所选文件列表创建一个zip文件,并使压缩后的文件可在Drupal 7中下载

Module 从所选文件列表创建一个zip文件,并使压缩后的文件可在Drupal 7中下载,module,drupal-7,hook,Module,Drupal 7,Hook,我有一个图像文件列表。我需要以zip格式归档这些文件,并使归档文件可下载。我看到了Drupal 7的系统模块中定义的ArchiverZip类。但我无法创建zip文件。在Drupal 7中如何执行此操作?是否有任何挂钩或自定义模块?请帮我解决这个问题 已更新 以下是代码: $zip = new ArchiverZip('archive.zip'); foreach($_POST['img'] as $fid): $query = db_select('file_managed', 'fn'

我有一个图像文件列表。我需要以zip格式归档这些文件,并使归档文件可下载。我看到了Drupal 7的
系统模块
中定义的
ArchiverZip
类。但我无法创建zip文件。在Drupal 7中如何执行此操作?是否有任何
挂钩
或自定义
模块
?请帮我解决这个问题

已更新

以下是代码:

$zip = new ArchiverZip('archive.zip');
foreach($_POST['img'] as $fid):
    $query = db_select('file_managed', 'fn')
            ->condition('fid', $fid)
            ->fields('fn', array('filename'));
    $result = $query->execute();

    foreach($result as $row) {
        if(file_exists('sites/default/files/'.$row->filename)){
            var_dump($zip->add($base_path.'sites/default/files/'.$row->filename));
        }
    }
 endforeach;
这反映了以下错误

异常:无法在ArchiverZip->\uuu construct()中打开archive.zip(basepath\modules\system\system.archiver.inc的第91行)。
请帮我做这个

在创建
ArchiverZip
类之前,我没有创建archive.zip文件,所以之前的归档操作失败了。现在代码如下所示:

$filename = 'archive.zip';
fopen($filename, 'w');
$zip = new ArchiverZip($filename);
foreach($_POST['img'] as $fid):
    $query = db_select('file_managed', 'fn')
            ->condition('fid', $fid)
            ->fields('fn', array('filename'));
    $result = $query->execute();

    foreach($result as $row) {
        if(file_exists('sites/default/files/'.$row->filename)){
            $zip->add($base_path.'sites/default/files/'.$row->filename);
        }
    }
 endforeach;

这个问题似乎是一个重复的问题