0

I am trying to build a web app where users can use OpenLayers to draw features and then save them either as a download or write to a file on the server which I can collect when I need it. I am happy with the OL3 bit so far. From reading around it seems AJAX is the way to do this so I have managed to included a button in my HMTL which runs a function that runs a php file to create a new file.I was pretty happy that I managed to get an empty text file as a start. So how do I get that file to contain the JSON information? I assume I need to send it from the JS world to PHP somehow?

The Function

function loadXMLDoc()
{
var xmlhttp=new XMLHttpRequest();

xmlhttp.open("GET","run.php",true);
xmlhttp.send();
}
</script>

The button

<button type="button" onclick="loadXMLDoc()">do something</button>

The PHP file (run.php)

<?php
$myfile = fopen("store/anothernewfile.geojson", "w") or die("Unable to open file!");
$txt = ['lyr_site'];
fwrite($myfile, $txt);
fclose($myfile);
?>

I don't have a geoserver and don't think it is really necessary for something simple like this, using .geojson files seems to be working so far.

  • think this is a more programming question than GIS? but would use a database to save the data with php like stackoverflow.com/questions/2467945/… – Mapperz Sep 9 '15 at 14:31
  • I am trying to keep things simple so no geoserver and no databases. A nice person on stack overflow pointed me in the right direction. link – Sethinacan Sep 10 '15 at 8:55
  • Is this solved? – Jonatas Walker Sep 11 '15 at 9:39
  • Yep - I put a link in my comment. I have it all working. – Sethinacan Sep 11 '15 at 10:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.