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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Dec 8 08:51:42 EST 2009


Author: kmq
Date: 2009-12-08 08:51:41 -0500 (Tue, 08 Dec 2009)
New Revision: 5083

Added:
   trunk/mapbender/http/php/mod_echo.php
   trunk/mapbender/http/php/mod_echoFileUpload.php
Log:
servide files for working with saving a loading wfs collections in the gazetteer

Added: trunk/mapbender/http/php/mod_echo.php
===================================================================
--- trunk/mapbender/http/php/mod_echo.php	                        (rev 0)
+++ trunk/mapbender/http/php/mod_echo.php	2009-12-08 13:51:41 UTC (rev 5083)
@@ -0,0 +1,57 @@
+<?php
+require_once(dirname(__FILE__)."/../php/mb_validateSession.php");
+require_once(dirname(__FILE__)."/../classes/class_json.php");
+
+
+
+if($_SERVER['REQUEST_METHOD'] == "POST") {
+	$ajaxResponse = new AjaxResponse($_POST);
+	try{
+		switch ($ajaxResponse->getMethod()) {
+
+			case "createFile":
+				$data = $ajaxResponse->getParameter('data');
+				$fileId = createFile($data);
+				$url = "../../http/tmp/$fileId";
+				if ($fileid === false){
+					throw new Exception("could not create file");
+				}
+				$result = array('url'=>$url);
+			break;
+
+			default:
+				throw new Exception("method invalid");
+
+		}
+		$ajaxResponse->setSuccess(true);
+		$ajaxResponse->setResult($result);
+	}
+	catch (Exception $E){
+		$ajaxResponse->setSuccess(false);
+		$ajaxResponse->setMessage($E->getMessage(). " [". $E->getLine() ."]");
+
+	}
+
+	$ajaxResponse->send();
+
+}else if ($_SERVER['REQUEST_METHOD'] == "GET"){
+	ob_start();
+		$fileid = $_GET['file'];
+		header("Content-Type","application/x-json");
+		header("Content-Disposition", "attachment; filename=\"".  $filename ."\"");
+		$result = file_get_contents(realpath(dirname(__FILE__)."/../../http/tmp/$id"));
+		print $result;
+	ob_end_flush();
+} 
+
+function createFile($data){
+	$filename = sha1(date("Y-m-d-His".rand())).".gjson";
+	$filepath = dirname(__FILE__)."/../../http/tmp/$filename";
+	$e 	= new mb_exception( $filepath);
+	if (file_put_contents($filepath,$data) === false){
+		return false;
+	}
+	return $filename;
+}
+
+?>

Added: trunk/mapbender/http/php/mod_echoFileUpload.php
===================================================================
--- trunk/mapbender/http/php/mod_echoFileUpload.php	                        (rev 0)
+++ trunk/mapbender/http/php/mod_echoFileUpload.php	2009-12-08 13:51:41 UTC (rev 5083)
@@ -0,0 +1,60 @@
+<?php
+require_once(dirname(__FILE__)."/../php/mb_validateSession.php");
+require_once(dirname(__FILE__)."/../classes/class_json.php");
+
+/*
+	copies an uploaded file from a field called 'geoJSONUpload'
+	to temporary directoery and returns an url to it
+*/
+
+if($_SERVER['REQUEST_METHOD'] == "POST") {
+	$url = "";
+	$error = "";
+	$filename = "wfs_upload".sha1(date("Y-m-d-His".rand())).".gjson";
+	$filepath = dirname(__FILE__)."/../tmp/$filename";
+	if(copy($_FILES['geoJSONUpload']['tmp_name'],$filepath) === False){
+		$error =  $_FILES['geoJSONUpload']['tmp_name'] ."-> $filepath";
+	}else{
+		$url  = "/../tmp/".$filename;
+	}
+	echo getForm($url,$error);
+
+}else if ($_SERVER['REQUEST_METHOD'] == "GET"){
+	echo getForm("","");
+} 
+
+
+
+function getForm($url,$error)
+{
+$form = <<<FORM
+	<html>
+	<head>
+	<script>
+	function loadResult(){
+		var url = document.forms[0].url.value;
+		if(url == ""){
+			alert("$error");
+		}else{
+			alert(url);
+		}
+	}
+	</script>
+	<head>
+	<body onload="loadResult(event);">
+		<span>$error</span>
+		<form name="uploadWfsResults"  id="uploadWfsResults" action="../php/mod_echoFileUpload.php" method="post">
+		<label for="geoJSONUpload">Upload WFsResults</label><input type="file" name="geoJSONUpload" />
+		<input type="hidden" name="url" value="$url" />
+		<input type="submit" />
+		</form>
+	</body>
+	</html>
+
+FORM;
+return $form;
+
+}
+
+
+?>



More information about the Mapbender_commits mailing list