[OSM-dev] PHP code

Nick Whitelegg nick at hogweed.org
Sat Jul 29 13:38:49 BST 2006


On Saturday 29 Jul 2006 12:14, OJW wrote:
> Does anyone have a snippet of PHP code for adding a node to openstreetmap?
> I'm having trouble figuring out how to do the PUT request in a way that the
> API understands...
>
> _______________________________________________
> dev mailing list
> dev at openstreetmap.org
> http://lists.openstreetmap.org/cgi-bin/mailman/listinfo/dev

Using cURL, this will take some OSM XML ($osm) and send it to API call 
$osmapicall. $ver is the OSM version.
From what I remember, with cURL you couldn't just stream data across without 
saving it to a temporary file first.

Nick

--

function uploadToOSM($osmapicall,$osm,$ver)
{
    $resp=0;
    $t=time();
    $fp = fopen("/var/www-data/tmp$t.osm","w");

    fwrite($fp,$osm);
    fclose($fp);
    $fp=fopen("/var/www-data/tmp$t.osm","r");

    $url = "http://www.openstreetmap.org/api/$ver/$osmapicall";

    $ch=curl_init ($url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch,CURLOPT_HEADER,false);
    curl_setopt($ch,CURLOPT_USERPWD,OSM_LOGIN);
    curl_setopt($ch,CURLOPT_PUT,true);
    curl_setopt($ch,CURLOPT_INFILE,$fp);
    curl_setopt($ch,CURLOPT_INFILESIZE,filesize("/var/www-data/tmp$t.osm"));
    $resp=curl_exec($ch);
    curl_close($ch);

    fclose($fp);
    return $resp;
}




More information about the dev mailing list