-
Notifications
You must be signed in to change notification settings - Fork 0
/
zip-files.php
37 lines (29 loc) · 1002 Bytes
/
zip-files.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
/**
* @param files
* @link http://php.net/manual/en/class.ziparchive.php
*
* @return String the path of the newly created zip archive.
*/
function tcp_zip_files($filenames, $imagesFolderPath)
{
$zip = new ZipArchive();
$dir = get_template_directory();
// The should be a directory /zip in the theme template directory.
$newFile = "/zip/files_" . date('d_m_h-i-s') . ".zip";
$filename = $dir . $newFile;
if ($zip->open($filename, ZIPARCHIVE::CREATE) !== true) {
exit("cannot open <$filename>\n");
}
foreach ($filenames as $key => $file) {
if (!$zip->addFile($file, basename($key))) {
if (!file_exists($file)) {
echo "<span style='color: red;' >" . $key . ": File does not exist. </span><br/>";
} else {
echo "<span style='color: red;' >" . $key . ": File exists, but can't add to zip archive</span><br/>";
}
}
}
$zip->close();
return $newFile;
}