From 87057fc33dfeee1b924947533c43f8c5a5a64e11 Mon Sep 17 00:00:00 2001 From: Felix Friedrich Date: Sat, 28 Sep 2013 12:21:23 +0200 Subject: [PATCH] A zip plugin --- plugins/_disabled/zip/after_content.php | 1 + plugins/_disabled/zip/style.css | 3 + plugins/_disabled/zip/zip.php | 95 +++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 plugins/_disabled/zip/after_content.php create mode 100644 plugins/_disabled/zip/style.css create mode 100644 plugins/_disabled/zip/zip.php diff --git a/plugins/_disabled/zip/after_content.php b/plugins/_disabled/zip/after_content.php new file mode 100644 index 0000000..5bd1f2b --- /dev/null +++ b/plugins/_disabled/zip/after_content.php @@ -0,0 +1 @@ +
">Download (.zip)
diff --git a/plugins/_disabled/zip/style.css b/plugins/_disabled/zip/style.css new file mode 100644 index 0000000..d841d3c --- /dev/null +++ b/plugins/_disabled/zip/style.css @@ -0,0 +1,3 @@ +#download { + font-size: 10pt; +} diff --git a/plugins/_disabled/zip/zip.php b/plugins/_disabled/zip/zip.php new file mode 100644 index 0000000..df82efe --- /dev/null +++ b/plugins/_disabled/zip/zip.php @@ -0,0 +1,95 @@ +. +*/ +/* + This script creates a zip file from a given folder (and subfolders). + Call it like http(s)://URL_OF_BIZOU/zip.php/FOLDER + where FOLDER is a folder in BIZOU_DIR/images. +*/ + +$bizouRootFromHere = '../..'; +require "$bizouRootFromHere/config.php"; + +/* + This function add a given folder (and it's subfolders) to an + existing zip archive. +*/ +function zipFolder($zip, $folder) { + global $bizouRootFromHere; + + $zip->addEmptyDir($folder); + $path = "$bizouRootFromHere/".IMAGES_DIR."/".$folder."/"; + + foreach (scandir($path) as $entry) { + + if (($entry != '.') and ($entry != '..')) { + + if (is_dir($path.$entry)) { + zipFolder($zip, $folder."/".$entry); + } else { + $zip->addFile($path.$entry, $folder."/".$entry); + } + } + } +} + +/* + Setting some needed variables. +*/ +$folder = $_SERVER["PATH_INFO"]; +$folder = trim($folder, "/"); + +if (($folder == "/") or ($folder == "")) { + $filename = "all.zip"; +} +else { + $filename = $folder.".zip"; +} + +if (is_dir("$bizouRootFromHere/".IMAGES_DIR."/".$folder)) { + + $tmp = tempnam("/tmp", "bizou_"); // Getting a temporary file. + unlink($tmp); // Deleting the temporary file in order to recreate it as a zip archive. + + // Creating zip archive. + $zip = new ZipArchive(); + if ($zip->open($tmp, ZIPARCHIVE::CREATE) !== TRUE) { + die("Cannot open temorary file :-("); + } + + // Adding the given folder to the zip archive. + zipFolder($zip, $folder); + + $zip->close(); + + // Returning zip file for downloading. + header('Content-type: application/zip'); + header('Content-Disposition: attachment; filename="'.$filename.'"'); + readfile($tmp); + unlink($tmp); + +} else { + + /* + The given folder does not seem to be a folder in BIZOU_DIR/images, + this we die. + */ + header('HTTP/1.1 404 Not Found'); + die("Gallery does not exist. Go away!"); +} +?> -- 1.7.10.4