\n"; print "\n"; print " \n"; print " \n"; print " openstreetmap.cz image upload\n"; print " \n"; print " \n"; print " "; print " \n"; } ################################################################################ function page_footer() ################################################################################ { print " \n"; print "\n"; } ################################################################################ function show_upload_dialog() ################################################################################ { $PHP_SELF = $_SERVER['PHP_SELF']; print"\n"; print " \n"; print "
\n"; print "

Uploading...

"; print ""; } ################################################################################ function insert_to_db($lat, $lon, $url ,$file, $author) ################################################################################ { global $global_error_message; $database = new SQLiteDatabase('guidepost', 0777, $error); if (!$database) { $global_error_message = (file_exists($yourfile)) ? "Impossible to open, check permissions" : "Impossible to create, check permissions"; return 0; } $q = "insert into guidepost values (NULL, '$lat', '$lon', '$url', '$file', '$author')"; $query = $database->queryExec($q, $query_error); if ($query_error) { $global_error_message = "Error: $query_error"; return 0; } if (!$query) { $global_error_message = "Impossible to execute query."; return 0; }; return 1; } ################################################################################ function process_file() ################################################################################ { global $_POST; global $global_error_message; $result = 0; $filename = $_FILES['uploadedfile']['name']; $error_message = ""; print "
name:"; print $filename; print "
type:"; print $_FILES['uploadedfile']['type']; print "
size:"; print $_FILES['uploadedfile']['size']; print "
tmp:"; print $_FILES['uploadedfile']['tmp_name']; print "
error"; print $_FILES['uploadedfile']['error']; print "
"; print $_POST['lat']; print $_POST['lon']; $lat = $_POST['lat']; $lon = $_POST['lon']; $author = $_POST['author']; print "
"; $file = basename($filename); $target_path = "uploads/"; $target_path = $target_path . $file; $final_path = "img/guidepost/" . $file; print "
target:$target_path"; print "
"; $error_message = "OK"; if (file_exists($_FILES['uploadedfile']['tmp_name'])) { print "existuje\n"; $result = 1; } else { $error_message = "nepodarilo se uploadnout soubor"; $result = 0; } if ($result) { if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "Soubor '$file' byl uspesne nahran na server do $target_path"; if (!$lat && !$lon) { $out = system ("/var/www/exifme.pl $target_path $author img/guidepost/", $errlvl); print "
vystup: $out"; if ($errlvl) { $result = 0; $error_message = "nepodarilo se zjistit souradnice z exif" + $out; } else { $result = 1; } } else { if (!copy ("uploads/$file","img/guidepost/$file")) { $error_message = "failed to copy $file to destination ..."; $result = 0; } else { $ret_db = insert_to_db($lat, $lon, $final_path, $file, $author); if (!$ret_db) { $error_message = "failed to insert to db" . $global_error_message; $result = 0; } } } } else { $error_message = "Chyba pri otevirani souboru, mozna je prilis velky"; $result = 0; } } print " \n"; return $result; } ################################################################################ function create_db() ################################################################################ { global $db; global $create_query; $create_query = "CREATE TABLE guidepost ( id int, lat numeric, lon numeric, url varchar, name varchar, PRIMARY KEY (id) );"; $db->queryExec($create_query); $db->queryExec("insert into guidepost values (NULL, 50.1, 17.1, 'x', 'znacka');"); $db->queryExec("insert into guidepost values (NULL, 50.2, 17.2, 'x', 'znacka');"); $db->queryExec("insert into guidepost values (NULL, 50.3, 17.3, 'x', 'znacka');"); $db->queryExec("insert into guidepost values (NULL, 50.4, 17.4, 'x', 'znacka');"); } $action = get_param("action"); switch ($action) { case "show_dialog": page_header(); show_upload_dialog(); page_footer(); break; case "file": page_header(); process_file(); page_footer(); break; case "": $bbox = get_param('bbox'); if ($bbox == "") { system("/usr/bin/logger no bbox"); die("No bbox provided\n"); } list($minlon, $minlat, $maxlon, $maxlat) = preg_split('/,/', $bbox, 4); $db = new SQLiteDatabase('guidepost'); if ($db) { $i = 0; $query = "select * from guidepost where lat < $maxlat and lat > $minlat and lon < $maxlon and lon > $minlon"; #print $query; $result = $db->arrayQuery($query, SQLITE_ASSOC); foreach ($result as $entry) { $result[$i++] = $entry; } print json_encode($result); } else { die($err); } break; } ?>