diff --git a/admin/php/metaestat_uploadcsv_submit.php b/admin/php/metaestat_uploadcsv_submit.php index df29137..7797a1a 100644 --- a/admin/php/metaestat_uploadcsv_submit.php +++ b/admin/php/metaestat_uploadcsv_submit.php @@ -65,6 +65,8 @@ if (ob_get_level() == 0) ob_start(); $colunas = explode(",",$buffer); $separador = ","; } + echo "
Separador de colunas identificado: ".$separador."
"; + echo "Total de colunas: ".count($colunas)."
"; //var_dump($colunas); fclose ($handle); //le o csv em um array @@ -79,14 +81,22 @@ if (ob_get_level() == 0) ob_start(); $buffer = str_replace("'",'',$buffer); $buffer = str_replace("\n",'',$buffer); $buffer = str_replace("\r",'',$buffer); - $temp = explode($separador,$buffer); - if(count($temp) == $ncolunas) - $linhas[] = $temp; + if($buffer != ""){ + $temp = explode($separador,$buffer); + if(count($temp) == $ncolunas){ + $linhas[] = $temp; + } + else{ + echo "A linha abaixo apresentou um erro - número de colunas não bate com o cabeçalho
"; + var_dump($temp); + exit; + } + } } } fclose ($handle); //decobre o tipo de coluna - $testar = 10; + $testar = 500; if(count($linhas) < $testar){ $testar = count($linhas); } @@ -126,6 +136,8 @@ if (ob_get_level() == 0) ob_start(); if($encodingdb == "LATIN1"){ $encodingdb = "ISO-8859-1"; } + echo "Codificação do banco: ".$encodingdb."
"; + //gera o script para criar a tabela e verifica se ja existe $sql = "SELECT table_name FROM information_schema.tables where table_schema = '".$_POST["i3GEOuploadcsvesquema"]."' AND table_name = '".$_POST["tabelaDestinocsv"]."'"; $res = $dbh->query($sql,PDO::FETCH_ASSOC); @@ -152,7 +164,7 @@ if (ob_get_level() == 0) ob_start(); if(!empty($_POST["comentarioCsv"])){ $enc = mb_detect_encoding($texto); $_POST["comentarioCsv"] = mb_convert_encoding($_POST["comentarioCsv"],$encodingdb,$enc); - $sqltabela[] = "COMMENT ON TABLE ".$_POST["i3GEOuploadcsvesquema"].".".$_POST["tabelaDestinocsv"]." IS '".$_POST["comentarioCsv"]."'"; + $sqltabela[] = "COMMENT ON TABLE ".$_POST["i3GEOuploadcsvesquema"].".".$_POST["tabelaDestinocsv"]." IS '".addcslashes($_POST["comentarioCsv"])."'"; } echo ""; var_dump($sqltabela); @@ -183,20 +195,19 @@ if (ob_get_level() == 0) ob_start(); $nlinhas = count($linhas); $valorX = 0; $valorY = 0; + $escapar = "',<,>,%,#,@,(,)"; for ($i=0; $i<$nlinhas;$i++){ $s = $linhas[$i]; + $enc = mb_detect_encoding($s); + if($enc != ""){ + $s = mb_convert_encoding($s,$encodingdb,$enc); + } $vs = array(); for ($j=0; $j<$ncolunas;$j++){ if($tipoColuna[$colunas[$j]] == "varchar"){ $texto = $s[$j]; $texto = str_replace("'","",$texto); - $enc = mb_detect_encoding($texto); - if(enc != ""){ - $texto = "'".mb_convert_encoding($texto,$encodingdb,$enc)."'"; - } - else{ - $texto = "'".$texto."'"; - } + $texto = "'".addcslashes($texto,$escapar)."'"; if($texto == "''"){ $texto = 'null'; } diff --git a/admin/php/metaestat_uploadshp_submit.php b/admin/php/metaestat_uploadshp_submit.php index 38c0f0d..011304c 100755 --- a/admin/php/metaestat_uploadshp_submit.php +++ b/admin/php/metaestat_uploadshp_submit.php @@ -92,11 +92,9 @@ if (isset($_FILES['i3GEOuploadshp']['name'])){ $sqinsert = array(); //verifica o tipo de coluna $tipoColuna = array(); - if($numshapes < 10){ - $testar = $numshapes; - } - else{ - $testar = 10; + $testar = $numshapes; + if($numshapes > 500){ + $testar = 500; } foreach($colunas as $coluna){ $tipo = "numeric"; @@ -188,6 +186,7 @@ if (isset($_FILES['i3GEOuploadshp']['name'])){ flush(); sleep(1); $srid = 4326; + $escapar = "'"; for ($i=0; $i<$numshapes;$i++){ $s = $layer->getShape(new resultObj($i)); $vs = array(); @@ -195,9 +194,10 @@ if (isset($_FILES['i3GEOuploadshp']['name'])){ if($tipoColuna[$coluna] == "varchar"){ $texto = $s->getValue($layer,$coluna); //echo $i." - ".mb_detect_encoding($texto)."
"; - $texto = str_replace("'","",$texto); + //$texto = str_replace("'","",$texto); $enc = mb_detect_encoding($texto); - if(enc != ""){ + $texto = addcslashes($texto,$escapar); + if($enc != ""){ $texto = "'".mb_convert_encoding($texto,$encodingdb,$enc)."'"; } else{ -- libgit2 0.21.2