From fe229655401abfa5aea2dc6c8830c8b9ed71aa64 Mon Sep 17 00:00:00 2001 From: moehm Date: Sun, 19 Oct 2014 06:59:54 +0200 Subject: Download zip archiv with all images. --- action.php | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'action.php') diff --git a/action.php b/action.php index e2d0098..f15f776 100644 --- a/action.php +++ b/action.php @@ -342,7 +342,7 @@ JG Adlershof"; } lredirect( "gallery;gallery=".htmlentities($_GET["gallery"]) ); if ( ! isset($_GET["gallery"]) || $_GET["gallery"] == "" ){ - redirect( "gallery;gallery=".htmlentities($_GET["gallery"]) ); + redirect( "gallery;gallery=".htmlentities($_SESSION["gallery"]) ); } rrmdir( IMAGE_PATH . $_GET["gallery"] ); $sql = $db->prepare("DELETE FROM " . DBPREFIX . "gallery WHERE id = %d;", $_GET["gallery"]); @@ -350,6 +350,38 @@ JG Adlershof"; $c->flush2(); redirect("foto"); break; + case("downloadGallery"): + if ( $_SERVER['REQUEST_METHOD'] != 'POST' ){ + header($_SERVER["SERVER_PROTOCOL"] . " 405 Method Not Allowed"); + ob_clean(); + echo "Method not allowed"; + exit; + } + lredirect( "gallery;gallery=".htmlentities($_GET["gallery"]) ); + if ( ! isset($_GET["gallery"]) || $_GET["gallery"] == "" || ! preg_match("/^[0-9]+$", $_GET["gallery"]) ){ + redirect( "gallery;gallery=".htmlentities($_SESSION["gallery"]) ); + } + $zname = '/tmp/jg_fotoalbum_'.$_GET["gallery"]; + $zip = new ZipArchive; + if ( $zip->open($zname) === TRUE ){ + $images = array_diff( scandir(IMAGE_PATH . $_GET["gallery"]), array('..', '.') ); + foreach( $images as $image){ + if ( is_file($image) ){ + $zip->addFile($image, basename($image)); + } + } + $zip->close(); + ob_end_clean(); + header("Content-Type: application/zip"); + header("Content-Length: " . filesize($zname)); + header("Content-Disposition: attachment; filename=jg_fotoalbum_".$_GET["gallery"]); + readfile($zname); + unlink($zname); + exit; + } else { + redirect("gallery&gallery=".$_GET["gallery"]); + } + break; default: print_404(); break; -- cgit v1.2.3