break; case 8: $output = "A PHP extensioned the file upload"; break; } return $output; } function cleanup() { $cleartmp = shell_exec('rm /tmp/' . $_FILES["csv"]["name"]); echo $cleartmp; } //array for storing upload status $upload = array("csv" => 0); //call function to process each upload $upload["csv"] = uploadProcess("csv"); //perform action and remove temp files in directory if ($upload["csv"] == 0) { //display error message echo "Error during CSV file upload! CSV database insertion halted."; cleanup(); } else { //open file for reading $file = fopen("/tmp/" . $_FILES["csv"]["name"], "r"); if ($file) { echo "File opened successfully.<br>"; //create db connection $dbconn = pg_connect("host=" . $dbhost . " port=" . $dbport . " dbname=" . $dbname . " user="******" password="******"Could not connect to server\n"); while (($line = fgets($file)) !== false) { //echo $line; $lineary = explode(";", $line);
break; } return $output; } function cleanup() { $cleartmp = shell_exec('rm /tmp/' . $_FILES["shp"]["name"] . ' /tmp/' . $_FILES["shx"]["name"] . ' /tmp/' . $_FILES["dbf"]["name"] . ' /tmp/' . $_FILES["prj"]["name"] . ' /tmp/' . substr($_FILES["shp"]["name"], 0, -4) . '.sql' . ' /tmp/insert' . substr($_FILES["shp"]["name"], 0, -4) . '.sql' . ' /tmp/insert2' . substr($_FILES["shp"]["name"], 0, -4) . '.sql'); echo $cleartmp; } //array for storing upload status $upload = array("shp" => 0, "shx" => 0, "dbf" => 0, "prj" => 0); //call function to process each upload $upload["shp"] = uploadProcess("shp"); $upload["shx"] = uploadProcess("shx"); $upload["dbf"] = uploadProcess("dbf"); $upload["prj"] = uploadProcess("prj"); //perform action and remove temp files in directory if ($upload["shp"] == 0 || $upload["shx"] == 0 || $upload["dbf"] == 0 || $upload["prj"] == 0) { //display error message echo "Error during shapefile upload! Shapefile database insertion halted."; cleanup(); } else { //check for filename mismatch if (substr($_FILES["shp"]["name"], 0, -4) != substr($_FILES["shx"]["name"], 0, -4) || substr($_FILES["shp"]["name"], 0, -4) != substr($_FILES["dbf"]["name"], 0, -4) || substr($_FILES["shp"]["name"], 0, -4) != substr($_FILES["prj"]["name"], 0, -4)) { echo "Base Filename mismatch! Make sure all files are from the same shapefile.<br>Shapefile database insertion halted."; } else { //generate raw insertion .sql $sqlconv = shell_exec('shp2pgsql -s 4326 /tmp/' . $_FILES["shp"]["name"] . ' > /tmp/' . substr($_FILES["shp"]["name"], 0, -4) . '.sql'); echo $sqlconv; //grep to select only insert statements $grepins = shell_exec('grep -e "INSERT INTO" /tmp/' . substr($_FILES["shp"]["name"], 0, -4) . '.sql > /tmp/insert' . substr($_FILES["shp"]["name"], 0, -4) . '.sql');