Commit 8e0a5de3c20368b67435793fee4faf174f380469
1 parent
055d3a67
Exists in
master
and in
7 other branches
Inclusão de opção para upload completo de um arquivo csv e criação de tabela no …
…postgresql (sistema metaestat)
Showing
5 changed files
with
183 additions
and
164 deletions
Show diff stats
admin/admin.db
No preview for this file type
admin/html/estat_editor.html
... | ... | @@ -5,10 +5,10 @@ |
5 | 5 | <title>Conexao com banco de dados</title> |
6 | 6 | <style type="text/css"> |
7 | 7 | /*margin and padding on body element |
8 | - can introduce errors in determining | |
9 | - element position and are not recommended; | |
10 | - we turn them off as a foundation for YUI | |
11 | - CSS treatments. */ | |
8 | + can introduce errors in determining | |
9 | + element position and are not recommended; | |
10 | + we turn them off as a foundation for YUI | |
11 | + CSS treatments. */ | |
12 | 12 | body { |
13 | 13 | margin: 0; |
14 | 14 | padding: 0; |
... | ... | @@ -38,8 +38,8 @@ body { |
38 | 38 | </div> |
39 | 39 | <div class="ft"></div> |
40 | 40 | </div> |
41 | - <p> | |
42 | - Atenção: para poder editar o banco de dados, o usuário da conexão escolhida deve ter direitos de edição<br> | |
41 | + <p style="font-size:10px;"> | |
42 | + Atenção: para poder editar o banco de dados, o usuário da conexão escolhida deve ter direitos de edição. | |
43 | 43 | Apenas as tabelas e os dados existentes no esquema i3geo_metaestat podem ser editados</p> |
44 | 44 | <div id="i3GEOadminEditorConexao" style="left: -5px;"></div><br> |
45 | 45 | <div id="i3GEOadminEditorEsquema" style="left: -5px;"></div> |
... | ... | @@ -52,33 +52,33 @@ body { |
52 | 52 | <div id=logajax style="display: block"></div> |
53 | 53 | <script> |
54 | 54 | /* |
55 | - Title: Editor de tabelas do sistema de metadados estatísticos | |
55 | + Title: Editor de tabelas do sistema de metadados estatísticos | |
56 | 56 | |
57 | - Licenca: | |
57 | + Licenca: | |
58 | 58 | |
59 | - GPL2 | |
59 | + GPL2 | |
60 | 60 | |
61 | - i3Geo Interface Integrada de Ferramentas de Geoprocessamento para Internet | |
61 | + i3Geo Interface Integrada de Ferramentas de Geoprocessamento para Internet | |
62 | 62 | |
63 | - Direitos Autorais Reservados (c) 2006 Ministério do Meio Ambiente Brasil | |
64 | - Desenvolvedor: Edmar Moretti edmar.moretti@mma.gov.br | |
63 | + Direitos Autorais Reservados (c) 2006 Ministério do Meio Ambiente Brasil | |
64 | + Desenvolvedor: Edmar Moretti edmar.moretti@mma.gov.br | |
65 | 65 | |
66 | - Este programa é software livre; você pode redistribuí-lo | |
67 | - e/ou modificá-lo sob os termos da Licença Pública Geral | |
68 | - GNU conforme publicada pela Free Software Foundation; | |
66 | + Este programa é software livre; você pode redistribuí-lo | |
67 | + e/ou modificá-lo sob os termos da Licença Pública Geral | |
68 | + GNU conforme publicada pela Free Software Foundation; | |
69 | 69 | |
70 | - Este programa é distribuído na expectativa de que seja útil, | |
71 | - porém, SEM NENHUMA GARANTIA; nem mesmo a garantia implícita | |
72 | - de COMERCIABILIDADE OU ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA. | |
73 | - Consulte a Licença Pública Geral do GNU para mais detalhes. | |
74 | - Você deve ter recebido uma cópia da Licença Pública Geral do | |
75 | - GNU junto com este programa; se não, escreva para a | |
76 | - Free Software Foundation, Inc., no endereço | |
77 | - 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA. | |
70 | + Este programa é distribuído na expectativa de que seja útil, | |
71 | + porém, SEM NENHUMA GARANTIA; nem mesmo a garantia implícita | |
72 | + de COMERCIABILIDADE OU ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA. | |
73 | + Consulte a Licença Pública Geral do GNU para mais detalhes. | |
74 | + Você deve ter recebido uma cópia da Licença Pública Geral do | |
75 | + GNU junto com este programa; se não, escreva para a | |
76 | + Free Software Foundation, Inc., no endereço | |
77 | + 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA. | |
78 | 78 | |
79 | - Arquivo: | |
79 | + Arquivo: | |
80 | 80 | |
81 | - i3geo/admin/html/estat_editor.html | |
81 | + i3geo/admin/html/estat_editor.html | |
82 | 82 | */ |
83 | 83 | |
84 | 84 | //necessario para a ferramenta login e outras | ... | ... |
admin/html/estat_variavel.html
... | ... | @@ -5,10 +5,10 @@ |
5 | 5 | <title>Variaveis</title> |
6 | 6 | <style type="text/css"> |
7 | 7 | /*margin and padding on body element |
8 | - can introduce errors in determining | |
9 | - element position and are not recommended; | |
10 | - we turn them off as a foundation for YUI | |
11 | - CSS treatments. */ | |
8 | + can introduce errors in determining | |
9 | + element position and are not recommended; | |
10 | + we turn them off as a foundation for YUI | |
11 | + CSS treatments. */ | |
12 | 12 | body { |
13 | 13 | margin: 0; |
14 | 14 | padding: 0; |
... | ... | @@ -59,6 +59,7 @@ body { |
59 | 59 | <input onclick="relatorioCompleto()" type=button id=estatVariavelrelatorioCompleto |
60 | 60 | value="Relatório" /> |
61 | 61 | <br> |
62 | + <p style="font-size:10px;">Observação: caso algum mapa esteja aberto (em outra aba por exemplo) não se esqueça de recarregar o navegador após alterar alguma classificação. Isso é necessário para que o mapa reflita as alterações feitas, anulando eventuais arquivos em cache.</p> | |
62 | 63 | <p>Variáveis cadastradas:</p> |
63 | 64 | <div id="estatVariavelArvore" style="left: -5px;"></div> |
64 | 65 | <div id=logajax style="display: block"></div> |
... | ... | @@ -67,39 +68,39 @@ body { |
67 | 68 | </center> |
68 | 69 | <script> |
69 | 70 | /* |
70 | - Title: Cadatro de variáveis estatísticas | |
71 | + Title: Cadatro de variáveis estatísticas | |
71 | 72 | |
72 | - Veja também: | |
73 | + Veja também: | |
73 | 74 | |
74 | - <core.js> | |
75 | + <core.js> | |
75 | 76 | |
76 | - <estat_variaveis.js> | |
77 | + <estat_variaveis.js> | |
77 | 78 | |
78 | - Licenca: | |
79 | + Licenca: | |
79 | 80 | |
80 | - GPL2 | |
81 | + GPL2 | |
81 | 82 | |
82 | - i3Geo Interface Integrada de Ferramentas de Geoprocessamento para Internet | |
83 | + i3Geo Interface Integrada de Ferramentas de Geoprocessamento para Internet | |
83 | 84 | |
84 | - Direitos Autorais Reservados (c) 2006 Ministério do Meio Ambiente Brasil | |
85 | - Desenvolvedor: Edmar Moretti edmar.moretti@mma.gov.br | |
85 | + Direitos Autorais Reservados (c) 2006 Ministério do Meio Ambiente Brasil | |
86 | + Desenvolvedor: Edmar Moretti edmar.moretti@mma.gov.br | |
86 | 87 | |
87 | - Este programa é software livre; você pode redistribuí-lo | |
88 | - e/ou modificá-lo sob os termos da Licença Pública Geral | |
89 | - GNU conforme publicada pela Free Software Foundation; | |
88 | + Este programa é software livre; você pode redistribuí-lo | |
89 | + e/ou modificá-lo sob os termos da Licença Pública Geral | |
90 | + GNU conforme publicada pela Free Software Foundation; | |
90 | 91 | |
91 | - Este programa é distribuído na expectativa de que seja útil, | |
92 | - porém, SEM NENHUMA GARANTIA; nem mesmo a garantia implícita | |
93 | - de COMERCIABILIDADE OU ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA. | |
94 | - Consulte a Licença Pública Geral do GNU para mais detalhes. | |
95 | - Você deve ter recebido uma cópia da Licença Pública Geral do | |
96 | - GNU junto com este programa; se não, escreva para a | |
97 | - Free Software Foundation, Inc., no endereço | |
98 | - 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA. | |
92 | + Este programa é distribuído na expectativa de que seja útil, | |
93 | + porém, SEM NENHUMA GARANTIA; nem mesmo a garantia implícita | |
94 | + de COMERCIABILIDADE OU ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA. | |
95 | + Consulte a Licença Pública Geral do GNU para mais detalhes. | |
96 | + Você deve ter recebido uma cópia da Licença Pública Geral do | |
97 | + GNU junto com este programa; se não, escreva para a | |
98 | + Free Software Foundation, Inc., no endereço | |
99 | + 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA. | |
99 | 100 | |
100 | - Arquivo: | |
101 | + Arquivo: | |
101 | 102 | |
102 | - i3geo/admin/html/estat_variaveis.html | |
103 | + i3geo/admin/html/estat_variaveis.html | |
103 | 104 | */ |
104 | 105 | |
105 | 106 | //necessario para a ferramenta login e outras | ... | ... |
admin/js/estat_editor.js
... | ... | @@ -424,6 +424,7 @@ i3GEOadmin.editor = { |
424 | 424 | }, |
425 | 425 | uploadshp: { |
426 | 426 | inicia: function(){ |
427 | + i3GEOadmin.editor.esvaziaFormsUpload(); | |
427 | 428 | var onde = $i("i3GEOadmin_formupload"); |
428 | 429 | if(onde.innerHTML != ""){ |
429 | 430 | onde.innerHTML = ""; |
... | ... | @@ -471,12 +472,13 @@ i3GEOadmin.editor = { |
471 | 472 | }, |
472 | 473 | uploadcsv: { |
473 | 474 | inicia: function(){ |
475 | + i3GEOadmin.editor.esvaziaFormsUpload(); | |
474 | 476 | var onde = $i("i3GEOadmin_formuploadcsv"); |
475 | 477 | if(onde.innerHTML != ""){ |
476 | 478 | onde.innerHTML = ""; |
477 | 479 | return; |
478 | 480 | } |
479 | - $i("i3GEOadmin_formupload").innerHTML = i3GEOadmin.editor.uploadcsv.formulario(); | |
481 | + $i("i3GEOadmin_formuploadcsv").innerHTML = i3GEOadmin.editor.uploadcsv.formulario(); | |
480 | 482 | new YAHOO.widget.Button( |
481 | 483 | "i3GEOuploadcsvsubmit", |
482 | 484 | {onclick:{fn: i3GEOadmin.editor.uploadcsv.submit}} |
... | ... | @@ -506,6 +508,15 @@ i3GEOadmin.editor = { |
506 | 508 | $i("i3GEOuploadcsvesquema").value = $i("i3GEOadminesquema").value; |
507 | 509 | $i("i3GEOuploadcsvf").submit(); |
508 | 510 | } |
511 | + }, | |
512 | + esvaziaFormsUpload: function(){ | |
513 | + var csv = $i("i3GEOadmin_formuploadcsv"), | |
514 | + shp = $i("i3GEOadmin_formupload") | |
515 | + if(csv){ | |
516 | + csv.innerHTML = ""; | |
517 | + } | |
518 | + if(shp){ | |
519 | + shp.innerHTML = ""; | |
520 | + } | |
509 | 521 | } |
510 | - | |
511 | 522 | }; | ... | ... |
admin/php/metaestat_uploadcsv_submit.php
1 | 1 | <?php |
2 | 2 | /* |
3 | 3 | * Faz o upload de csv e insere no banco de dados criando uma nova tabela |
4 | - */ | |
4 | +*/ | |
5 | 5 | include_once("admin.php"); |
6 | 6 | include_once("login.php"); |
7 | 7 | if(verificaOperacaoSessao("admin/metaestat/editorbanco") == false){ |
... | ... | @@ -16,122 +16,128 @@ error_reporting(0); |
16 | 16 | <link rel="stylesheet" type="text/css" href="../../css/geral.css" /> |
17 | 17 | <title></title> |
18 | 18 | </head> |
19 | -<body bgcolor="white" style="background-color:white;text-align:left;"> | |
20 | -<p> | |
21 | -<?php | |
22 | -if($_POST["tabelaDestino"] == ""){ | |
23 | - echo "Nome da tabela não definido"; | |
24 | - exit; | |
25 | -} | |
26 | -if ($_FILES['i3GEOuploadcsv']['name'] == ""){ | |
27 | - echo "Arquivo não definido"; | |
28 | - exit; | |
29 | -} | |
30 | -if (isset($_FILES['i3GEOuploadcsv']['name'])){ | |
31 | - require_once ("../../ms_configura.php"); | |
32 | - echo "<p class='paragrafo' >Carregando o arquivo...</p>"; | |
33 | - $arqcsv = $_FILES['i3GEOuploadcsv']['tmp_name']; | |
34 | - $nomePrefixo = str_replace(" ","_",removeAcentos($_FILES['i3GEOuploadcsv']['name'])); | |
35 | - $nomePrefixo = $nomePrefixo."_".(nomeRandomico(4)); | |
36 | - | |
37 | - $Arquivo = $_FILES['i3GEOuploadcsv']['tmp_name']; | |
38 | - $status = move_uploaded_file($Arquivo,$dir_tmp."/".$nomePrefixo); | |
39 | - if($status != 1) | |
40 | - {echo "<p class='paragrafo' >Ocorreu um erro no envio do arquivo";exit;} | |
41 | - | |
19 | +<body bgcolor="white" style="background-color: white; text-align: left;"> | |
20 | + <p> | |
21 | + <?php | |
22 | + if($_POST["tabelaDestinocsv"] == ""){ | |
23 | + echo "Nome da tabela não definido"; | |
24 | + exit; | |
25 | + } | |
26 | + if ($_FILES['i3GEOuploadcsv']['name'] == ""){ | |
27 | + echo "Arquivo não definido"; | |
28 | + exit; | |
29 | + } | |
30 | + if (isset($_FILES['i3GEOuploadcsv']['name'])){ | |
31 | + require_once ("../../ms_configura.php"); | |
32 | + echo "<p class='paragrafo' >Carregando o arquivo...</p>"; | |
33 | + $arqcsv = $_FILES['i3GEOuploadcsv']['tmp_name']; | |
34 | + $nomePrefixo = str_replace(" ","_",removeAcentos($_FILES['i3GEOuploadcsv']['name'])); | |
35 | + $nomePrefixo = $nomePrefixo."_".(nomeRandomico(4)); | |
42 | 36 | |
43 | - if(!file_exists($dir_tmp."/".$nomePrefixo)) | |
44 | - {echo "<p class='paragrafo' >Ocorreu algum problema no envio do arquivo ".$dir_tmp."/".$nomePrefixo;paraAguarde();exit;} | |
45 | - $arqcsv = $dir_tmp."/".$nomePrefixo; | |
37 | + $Arquivo = $_FILES['i3GEOuploadcsv']['tmp_name']; | |
38 | + $status = move_uploaded_file($Arquivo,$dir_tmp."/".$nomePrefixo); | |
39 | + if($status != 1){ | |
40 | + echo "<p class='paragrafo' >Ocorreu um erro no envio do arquivo";exit; | |
41 | + } | |
42 | + if(!file_exists($dir_tmp."/".$nomePrefixo)){ | |
43 | + echo "<p class='paragrafo' >Ocorreu algum problema no envio do arquivo ".$dir_tmp."/".$nomePrefixo;paraAguarde();exit; | |
44 | + } | |
45 | + $arqcsv = $dir_tmp."/".$nomePrefixo; | |
46 | + //pega os parametros de conexao | |
47 | + include("classe_metaestat.php"); | |
48 | + $m = new Metaestat(); | |
49 | + $conexao = $m->listaConexao($_POST["i3GEOuploadcsvcodigoconexao"],true); | |
50 | + //pega a lista de colunas e identifica o separador utilizado | |
51 | + $handle = fopen ($arqcsv, "r"); | |
52 | + $cabecalho = fgets($handle); | |
53 | + $buffer = str_replace('"','',$cabecalho); | |
54 | + $buffer = str_replace("'",'',$buffer); | |
55 | + $buffer = str_replace("\n",'',$buffer); | |
56 | + $buffer = str_replace("\r",'',$buffer); | |
57 | + $colunas = explode(";",$buffer); | |
58 | + $separador = ";"; | |
59 | + if(count($colunas) == 1){ | |
60 | + $colunas = explode(",",$buffer); | |
61 | + $separador = ","; | |
62 | + } | |
63 | + //var_dump($colunas); | |
64 | + fclose ($handle); | |
65 | + //le o csv em um array | |
66 | + $handle = fopen ($arqcsv, "r"); | |
67 | + $linhas = array(); | |
46 | 68 | |
47 | - //pega os parametros de conexao | |
48 | - include("classe_metaestat.php"); | |
49 | - $m = new Metaestat(); | |
50 | - $conexao = $m->listaConexao($_POST["i3GEOuploadcodigoconexao"],true); | |
51 | - //pega a lista de colunas e identifica o separador utilizado | |
52 | - $handle = fopen ($arqcsv, "r"); | |
53 | - $cabecalho = fgets($handle); | |
54 | - $buffer = str_replace('"','',$cabecalho); | |
55 | - $buffer = str_replace("'",'',$buffer); | |
56 | - $buffer = str_replace("\n",'',$buffer); | |
57 | - $buffer = str_replace("\r",'',$buffer); | |
58 | - $colunas = explode(";",$buffer); | |
59 | - $separador = ";"; | |
60 | - if(count($colunas) == 1){ | |
61 | - $colunas = explode(",",$buffer); | |
62 | - $separador = ","; | |
63 | - } | |
64 | - //var_dump($colunas); | |
65 | - $colunas = implode(",",$colunas); | |
66 | - fclose ($handle); | |
67 | - | |
68 | - | |
69 | - //le o csv em um array | |
70 | - $handle = fopen ($arqcsv, "r"); | |
71 | - $linhas = array(); | |
72 | - while (!feof($handle)) { | |
73 | - $buffer = fgets($handle); | |
74 | - if($buffer != $cabecalho){ | |
75 | - $buffer = str_replace('"','',$buffer); | |
76 | - $buffer = str_replace("'",'',$buffer); | |
77 | - $buffer = str_replace("\n",'',$buffer); | |
78 | - $buffer = str_replace("\r",'',$buffer); | |
79 | - $linhas[] = explode($separador,$buffer); | |
69 | + $ncolunas = count($colunas); | |
70 | + while (!feof($handle)) { | |
71 | + $buffer = fgets($handle); | |
72 | + if($buffer != $cabecalho){ | |
73 | + $buffer = str_replace('"','',$buffer); | |
74 | + $buffer = str_replace("'",'',$buffer); | |
75 | + $buffer = str_replace("\n",'',$buffer); | |
76 | + $buffer = str_replace("\r",'',$buffer); | |
77 | + $temp = explode($separador,$buffer); | |
78 | + if(count($temp) == $ncolunas) | |
79 | + $linhas[] = $temp; | |
80 | + } | |
80 | 81 | } |
81 | - } | |
82 | - fclose ($handle); | |
83 | - //decobre o tipo de coluna | |
84 | - $ncolunas = count($colunas); | |
85 | - for ($j=0; $j<$ncolunas;$j++){ | |
86 | - $tipo = "numeric"; | |
87 | - for ($i=0; $i<$testar;$i++){ | |
88 | - $s = $linhas[$i]; | |
89 | - $v = $s[$j]; | |
90 | - if(!is_numeric($v)){ | |
91 | - $tipo = "varchar"; | |
82 | + fclose ($handle); | |
83 | + //decobre o tipo de coluna | |
84 | + $testar = 10; | |
85 | + if(count($linhas) < $testar){ | |
86 | + $testar = count($linhas); | |
92 | 87 | } |
93 | - } | |
94 | - $tipoColuna[$colunas[$j]] = $tipo; | |
95 | - } | |
96 | - echo "<br>Tipos das colunas: <pre>"; | |
97 | - var_dump($tipoColuna); | |
98 | - echo "</pre>"; | |
99 | - //gera o script para criar a tabela | |
100 | - $sqltabela = array(); | |
101 | - $sql = "CREATE TABLE ".$_POST["i3GEOuploadesquema"].".".$_POST["tabelaDestino"]."("; | |
102 | - foreach($colunas as $coluna){ | |
103 | - $sql .= ",".strtolower($coluna)." ".$tipoColuna[$coluna]; | |
104 | - } | |
105 | - $sql .= ")WITH(OIDS=FALSE)"; | |
106 | - $sqltabela[] = $sql; | |
107 | - $sqltabela[] = "ALTER TABLE ".$_POST["i3GEOuploadesquema"].".".$_POST["tabelaDestino"]." OWNER TO ".$conexao["usuario"]; | |
108 | - echo "<br>Sql tabela: <pre>"; | |
109 | - var_dump($sqltabela); | |
110 | - echo "</pre>"; | |
111 | - //gera o script para inserir os dados | |
112 | - $linhasql = array(); | |
113 | - $insert = "INSERT INTO ".$_POST["i3GEOuploadesquema"].".".$_POST["tabelaDestino"]."(".strtolower(implode(",",$colunas)).")"; | |
114 | - $nlinhas = count($linhas); | |
115 | - for ($i=0; $i<$nlinhas;$i++){ | |
116 | - $s = $linhas[$i]; | |
117 | - $vs = array(); | |
118 | - $vs[] = $i; | |
119 | - for ($j=0; $j<$ncolunas;$j++){ | |
120 | - if($tipoColuna[$colunas[$j]] == "varchar"){ | |
121 | - $vs[] = "'".$s[$j]."'"; | |
88 | + $tipoColuna = array(); | |
89 | + for ($j=0; $j<$ncolunas;$j++){ | |
90 | + $tipo = "numeric"; | |
91 | + for ($i=0; $i<$testar;$i++){ | |
92 | + $s = $linhas[$i]; | |
93 | + $v = $s[$j]; | |
94 | + if(!is_numeric($v)){ | |
95 | + $tipo = "varchar"; | |
96 | + } | |
97 | + } | |
98 | + $tipoColuna[$colunas[$j]] = $tipo; | |
122 | 99 | } |
123 | - else{ | |
124 | - $vs[] = $s[$j]; | |
100 | + echo "<br>Tipos das colunas: <pre>"; | |
101 | + var_dump($tipoColuna); | |
102 | + echo "</pre>"; | |
103 | + //gera o script para criar a tabela | |
104 | + $sqltabela = array(); | |
105 | + $sql = "CREATE TABLE ".$_POST["i3GEOuploadcsvesquema"].".".$_POST["tabelaDestinocsv"]."("; | |
106 | + $temp = array(); | |
107 | + foreach($colunas as $coluna){ | |
108 | + $temp[] = strtolower($coluna)." ".$tipoColuna[$coluna]; | |
125 | 109 | } |
126 | - } | |
127 | - $linhasql[] = $insert."VALUES(".implode(",",$vs).")"; | |
128 | - } | |
129 | - try { | |
130 | - $dbh = new PDO('pgsql:dbname='.$conexao["bancodedados"].';user='.$conexao["usuario"].';password='.$conexao["senha"].';host='.$conexao["host"].';port='.$conexao["porta"]); | |
131 | - } catch (PDOException $e) { | |
110 | + $sql .= implode(",",$temp).") WITH(OIDS=FALSE)"; | |
111 | + $sqltabela[] = $sql; | |
112 | + $sqltabela[] = "ALTER TABLE ".$_POST["i3GEOuploadcsvesquema"].".".$_POST["tabelaDestinocsv"]." OWNER TO ".$conexao["usuario"]; | |
113 | + echo "<br>Sql tabela: <pre>"; | |
114 | + var_dump($sqltabela); | |
115 | + echo "</pre>"; | |
116 | + //gera o script para inserir os dados | |
117 | + $linhasql = array(); | |
118 | + $insert = "INSERT INTO ".$_POST["i3GEOuploadcsvesquema"].".".$_POST["tabelaDestinocsv"]."(".strtolower(implode(",",$colunas)).")"; | |
119 | + $nlinhas = count($linhas); | |
120 | + for ($i=0; $i<$nlinhas;$i++){ | |
121 | + $s = $linhas[$i]; | |
122 | + $vs = array(); | |
123 | + for ($j=0; $j<$ncolunas;$j++){ | |
124 | + if($tipoColuna[$colunas[$j]] == "varchar"){ | |
125 | + $vs[] = "'".$s[$j]."'"; | |
126 | + } | |
127 | + else{ | |
128 | + $vs[] = $s[$j]; | |
129 | + } | |
130 | + } | |
131 | + $linhasql[] = $insert."VALUES(".implode(",",$vs).")"; | |
132 | + } | |
133 | + //echo "<pre>"; | |
134 | + //var_dump($linhasql);exit; | |
135 | + try { | |
136 | + $dbh = new PDO('pgsql:dbname='.$conexao["bancodedados"].';user='.$conexao["usuario"].';password='.$conexao["senha"].';host='.$conexao["host"].';port='.$conexao["porta"]); | |
137 | + } catch (PDOException $e) { | |
132 | 138 | echo 'Connection failed: ' . $e->getMessage(); |
133 | 139 | } |
134 | - | |
140 | + | |
135 | 141 | foreach($sqltabela as $linha){ |
136 | 142 | try { |
137 | 143 | $dbh->query($linha); |
... | ... | @@ -147,11 +153,12 @@ if (isset($_FILES['i3GEOuploadcsv']['name'])){ |
147 | 153 | } |
148 | 154 | } |
149 | 155 | echo "<br>Feito!!!<br>Faça o reload da página"; |
150 | -} | |
151 | -else{ | |
156 | + } | |
157 | + else{ | |
152 | 158 | echo "<p class='paragrafo' >Erro ao enviar o arquivo. Talvez o tamanho do arquivo seja maior do que o permitido.</p>"; |
153 | 159 | } |
154 | 160 | |
155 | 161 | ?> |
162 | + | |
156 | 163 | </body> |
157 | 164 | </html> | ... | ... |