GPX Upload Client

From OpenStreetMap Wiki
Jump to: navigation, search

Took a bit of trial and error with the cURL options to write a GPX upload client using PHP/cURL, but anyway, this does work:

<?php

$url = "http://www.openstreetmap.org/api/0.5/gpx/create";
$username="nick@hogweed.org";
$password="password";
$ch=curl_init ($url);
$formvars = array
    ("file"=>"@041107.gpx",
        "description"=>"Henley to Chithurst via Older Hill and Stedham",
        "tags"=>"West_Sussex footpaths",
        "public"=>1);

curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt ($ch, CURLOPT_HTTPHEADER,array("Expect:"));
curl_setopt ($ch,CURLOPT_USERPWD,"$username:$password");
curl_setopt($ch,CURLOPT_POST,1 );
curl_setopt($ch,CURLOPT_POSTFIELDS,$formvars);
$resp=curl_exec($ch);
$httpCode=curl_getinfo($ch,CURLINFO_HTTP_CODE);

echo "Response: $resp, HTTP code: $httpCode";

?>