我有一个图像文件列表。我需要以zip格式存档这些文件并使存档文件可下载。我在 Drupal 7 的ArchiverZip
中定义了system module
类。但我无法创建 zip 文件。我如何在 Drupal 7 中执行此操作?是否有hooks
或自定义modules
?请帮帮我。
已更新
以下是代码:
$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-> __ construct()中打开archive.zip( basepath \ modules \ system \ system.archiver.inc 的第91行)。 请帮我解决一下这个 。
答案 0 :(得分:0)
我在创建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;