On 19 March 2010 00:21, Bernhard zwischenbrugger <[email protected]> wrote:
> GPX is XML and there is no need for multipart/form-data upload.

GPX might be XML, but it's not HTTP, and if you want to upload a file
over HTTP you need to talk multipart/form...

> To debug that kind of uploads is not possible.

There is plenty of ways to debug, just like everything else it's a
skill set, in this case you need to sniff packets...

<?
        $user = 'username';
        $pass = 'password';
        $file = '/tmp/filename.gpx';

        $url = "/api/0.6/gpx/create";

                $file = trim($file);
                if($file == '')
                        continue;

                if(!file_exists($file))
                        continue;

                $boundary = '----------'.sha1(date("U").$fn.rand(0, date("U")));
                $fn = md5(basename(date("U").$file.$boundary));
                $cmd = "grep '<trkpt' '$file'|wc -l";
                $trackpoints = trim(`$cmd`);

                if($trackpoints >= 300)
                {
                        $body = "";
                        $fn .= '.gpx';
                        $data = gzencode(file_get_contents($file));

                        $body .= '--'.$boundary."\r\n";
                        $body .= "Content-Disposition: form-data; name=\"file\";
filename=\"$fn.gz\"\r\n\r\n";
                        $body .= $data."\r\n";
                        $body .= '--'.$boundary."\r\n";
                        $body .= "Content-Disposition: form-data; 
name=\"description\"\r\n\r\n";
                        $body .= "uploaded route.\r\n";
                        $body .= '--'.$boundary."\r\n";
                        $body .= "Content-Disposition: form-data; 
name=\"tags\"\r\n\r\n";
                        $body .= "automatic_upload ".date("Y F")."\r\n";
                        $body .= '--'.$boundary."\r\n";
                        $body .= "Content-Disposition: form-data; 
name=\"public\"\r\n\r\n";
                        $body .= "1\r\n";

                        $body .= '--'.$boundary."--\r\n";

                        $head  = "POST $url HTTP/1.1\r\n";
                        $head .= "host: www.openstreetmap.org\r\n";
                        $head .= "Transfer-Encoding: 8bit\r\n";
                        $head .= "Authorization: Basic 
".base64_encode($user.':'.$pass)."\r\n";
                        $head .= "Content-Length: ".strlen($body)."\r\n";
                        $head .= "Content-type: multipart/form-data; 
boundary=$boundary\r\n";
                        $head .= "Connection: close\r\n\r\n".$body;
                        //echo $head;

                        if(($fp = @fsockopen("www.openstreetmap.org", 80)) === 
FALSE)
                                continue;

                        fputs($fp, $head);
                        $line = $lastline = "";
                        $start = false;
                        while(!feof($fp))
                        {
                                $line = trim(fgets($fp));
                                if($start == false && $line == '')
                                {
                                        $start = true;
                                        continue;
                                }
                                if($start == false)
                                        continue;

                                $id = $line;
                                break;
                        }
                        fclose($fp);
                        if($id <= 0)
                                continue;
                }

_______________________________________________
dev mailing list
[email protected]
http://lists.openstreetmap.org/listinfo/dev

Reply via email to