A zip plugin
This commit is contained in:
parent
90f5657437
commit
87057fc33d
3 changed files with 99 additions and 0 deletions
1
plugins/_disabled/zip/after_content.php
Normal file
1
plugins/_disabled/zip/after_content.php
Normal file
|
@ -0,0 +1 @@
|
|||
<div id="download"><a href="<?php echo $GLOBALS['rootUrl']."plugins/zip/zip.php".$GLOBALS['simplePath']; ?>">Download</a> (.zip)</div>
|
3
plugins/_disabled/zip/style.css
Normal file
3
plugins/_disabled/zip/style.css
Normal file
|
@ -0,0 +1,3 @@
|
|||
#download {
|
||||
font-size: 10pt;
|
||||
}
|
95
plugins/_disabled/zip/zip.php
Normal file
95
plugins/_disabled/zip/zip.php
Normal file
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
/*
|
||||
Bizou zip plugin
|
||||
Copyright (C) 2013 Felix Friedrich
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/*
|
||||
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!");
|
||||
}
|
||||
?>
|
Loading…
Reference in a new issue