[Mapbender-commits] r5107 - trunk/mapbender/http/php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Dec 10 04:33:36 EST 2009


Author: verenadiewald
Date: 2009-12-10 04:33:35 -0500 (Thu, 10 Dec 2009)
New Revision: 5107

Added:
   trunk/mapbender/http/php/mod_download.php
Log:
download files

Added: trunk/mapbender/http/php/mod_download.php
===================================================================
--- trunk/mapbender/http/php/mod_download.php	                        (rev 0)
+++ trunk/mapbender/http/php/mod_download.php	2009-12-10 09:33:35 UTC (rev 5107)
@@ -0,0 +1,36 @@
+<?php
+
+ob_start();
+
+$download = array();
+
+$download["dir"]  = "../tmp/";
+$download["file"] = basename(trim($_REQUEST["download"]));
+if (!preg_match("/^[a-zA-Z0-9_-]+(\.[a-zA-Z0-9]+)$/", $download["file"]) 
+	|| !file_exists($download["dir"] . $download["file"])) {
+	die("Invalid filename.");
+}
+$download["file"] = $download["dir"] . $download["file"];
+
+if(!(bool)$download["file"]) {
+	die("No filename given.");
+}
+
+if((int)strpos($download["file"],"..") !== 0) {
+	die("Illegal filename given.");
+}
+
+if(!file_exists(implode($download)) || !is_readable(implode($download))) {
+	die("An error occured.");
+}
+
+$filename = $download["file"];
+
+
+header("Pragma: private");
+header("Cache-control: private, must-revalidate");
+header("Content-Type: x-type/subtype");
+header("Content-Disposition: attachment; filename=\"".$filename."\"");
+
+readfile(implode($download));
+?>
\ No newline at end of file



More information about the Mapbender_commits mailing list