4 Copyright (C) 2013 Felix Friedrich
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 This script creates a zip file from a given folder (and subfolders).
21 Call it like http(s)://URL_OF_BIZOU/zip.php/FOLDER
22 where FOLDER is a folder in BIZOU_DIR/images.
25 $bizouRootFromHere = '../..';
26 require "$bizouRootFromHere/config.php";
29 This function add a given folder (and it's subfolders) to an
32 function zipFolder($zip, $folder) {
33 global $bizouRootFromHere;
35 $zip->addEmptyDir($folder);
36 $path = "$bizouRootFromHere/".IMAGES_DIR."/".$folder."/";
38 foreach (scandir($path) as $entry) {
40 if (($entry != '.') and ($entry != '..')) {
42 if (is_dir($path.$entry)) {
43 zipFolder($zip, $folder."/".$entry);
45 $zip->addFile($path.$entry, $folder."/".$entry);
52 Setting some needed variables.
54 $folder = $_SERVER["PATH_INFO"];
55 $folder = trim($folder, "/");
57 if (($folder == "/") or ($folder == "")) {
58 $filename = "all.zip";
61 $filename = $folder.".zip";
64 if (is_dir("$bizouRootFromHere/".IMAGES_DIR."/".$folder)) {
66 $tmp = tempnam(ini_get("upload_tmp_dir"), "bizou_"); // Getting a temporary file.
67 unlink($tmp); // Deleting the temporary file in order to recreate it as a zip archive.
69 // Creating zip archive.
70 $zip = new ZipArchive();
71 if ($zip->open($tmp, ZIPARCHIVE::CREATE) !== TRUE) {
72 die("Cannot open temorary file :-(");
75 // Adding the given folder to the zip archive.
76 zipFolder($zip, $folder);
80 // Returning zip file for downloading.
81 header('Content-type: application/zip');
82 header('Content-Disposition: attachment; filename="'.$filename.'"');
89 The given folder does not seem to be a folder in BIZOU_DIR/images,
92 header('HTTP/1.1 404 Not Found');
93 die("Gallery does not exist. Go away!");