Commit a9f1c1c0d0803361fcee84d27966e4665808f4ab
1 parent
fd2e6af1
Exists in
master
correcao nas ferramentas de upload
Showing
5 changed files
with
79 additions
and
30 deletions
Show diff stats
admin/php/estat_mapa_upload.php
... | ... | @@ -8,6 +8,7 @@ error_reporting(0); |
8 | 8 | ?> |
9 | 9 | <html> |
10 | 10 | <head> |
11 | +<link rel="stylesheet" type="text/css" href="../../css/input.css" /> | |
11 | 12 | <link rel="stylesheet" type="text/css" href="../../css/geral.css" /> |
12 | 13 | <title></title> |
13 | 14 | </head> |
... | ... | @@ -27,7 +28,7 @@ if (isset($_FILES['uploadimagem']['name'])){ |
27 | 28 | //sobe arquivo |
28 | 29 | $Arquivo = $_FILES['uploadimagem']['tmp_name']; |
29 | 30 | //echo $Arquivo; |
30 | - $status = move_uploaded_file($Arquivo,$arq); | |
31 | + $status = move_uploaded_file($Arquivo,str_replace(".png","",$arq).".png"); | |
31 | 32 | if($status != 1) |
32 | 33 | {echo "<p class='paragrafo' >Ocorreu um erro no envio do arquivo. Verifique as permissoes de escrita";exit;} |
33 | 34 | if($status == 1){ | ... | ... |
admin/php/metaestat_mapa_uploadimagem.php
... | ... | @@ -12,6 +12,7 @@ error_reporting(0); |
12 | 12 | ?> |
13 | 13 | <html> |
14 | 14 | <head> |
15 | +<link rel="stylesheet" type="text/css" href="../../css/input.css" /> | |
15 | 16 | <link rel="stylesheet" type="text/css" href="../../css/geral.css" /> |
16 | 17 | <title></title> |
17 | 18 | </head> |
... | ... | @@ -31,12 +32,11 @@ if (isset($_FILES['uploadimagem']['name'])){ |
31 | 32 | //sobe arquivo |
32 | 33 | $Arquivo = $_FILES['uploadimagem']['tmp_name']; |
33 | 34 | //echo $Arquivo; |
34 | - $status = move_uploaded_file($Arquivo,$arq); | |
35 | + $status = move_uploaded_file($Arquivo,str_replace(".png","",$arq).".png"); | |
35 | 36 | if($status != 1) |
36 | 37 | {echo "<p class='paragrafo' >Ocorreu um erro no envio do arquivo. Verifique as permissoes de escrita";exit;} |
37 | 38 | if($status == 1){ |
38 | 39 | echo "<p class='paragrafo' >Arquivo enviado.</p>"; |
39 | - chmod($arq,0777); | |
40 | 40 | } |
41 | 41 | else{ |
42 | 42 | echo "<p class='paragrafo' >Erro ao enviar o arquivo.</p>"; | ... | ... |
admin/php/metaestat_uploadcsv_submit.php
... | ... | @@ -15,6 +15,7 @@ if (ob_get_level() == 0) ob_start(); |
15 | 15 | <html> |
16 | 16 | <head> |
17 | 17 | <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"> |
18 | +<link rel="stylesheet" type="text/css" href="../../css/input.css" /> | |
18 | 19 | <link rel="stylesheet" type="text/css" href="../../css/geral.css" /> |
19 | 20 | <title></title> |
20 | 21 | </head> |
... | ... | @@ -37,7 +38,7 @@ if (ob_get_level() == 0) ob_start(); |
37 | 38 | sleep(1); |
38 | 39 | $arqcsv = $_FILES['i3GEOuploadcsv']['tmp_name']; |
39 | 40 | $nomePrefixo = str_replace(" ","_",removeAcentos($_FILES['i3GEOuploadcsv']['name'])); |
40 | - $nomePrefixo = $nomePrefixo."_".(nomeRandomico(4)); | |
41 | + $nomePrefixo = $nomePrefixo."_".(nomeRandomico(4)).".csv"; | |
41 | 42 | |
42 | 43 | $Arquivo = $_FILES['i3GEOuploadcsv']['tmp_name']; |
43 | 44 | $status = move_uploaded_file($Arquivo,$dir_tmp."/".$nomePrefixo); |
... | ... | @@ -65,7 +66,8 @@ if (ob_get_level() == 0) ob_start(); |
65 | 66 | $colunas = explode(",",$buffer); |
66 | 67 | $separador = ","; |
67 | 68 | } |
68 | - //var_dump($colunas); | |
69 | + echo "<p class='paragrafo' >Separador de colunas identificado: <b>".$separador."</b></p>"; | |
70 | + echo "<p class='paragrafo' >Total de colunas: <b>".count($colunas)."</b></p>"; | |
69 | 71 | fclose ($handle); |
70 | 72 | //le o csv em um array |
71 | 73 | $handle = fopen ($arqcsv, "r"); |
... | ... | @@ -75,18 +77,26 @@ if (ob_get_level() == 0) ob_start(); |
75 | 77 | while (!feof($handle)) { |
76 | 78 | $buffer = fgets($handle); |
77 | 79 | if($buffer != $cabecalho){ |
78 | - $buffer = str_replace('"','',$buffer); | |
80 | + //$buffer = str_replace('"','',$buffer); | |
79 | 81 | $buffer = str_replace("'",'',$buffer); |
80 | 82 | $buffer = str_replace("\n",'',$buffer); |
81 | 83 | $buffer = str_replace("\r",'',$buffer); |
82 | - $temp = explode($separador,$buffer); | |
83 | - if(count($temp) == $ncolunas) | |
84 | - $linhas[] = $temp; | |
84 | + if($buffer != ""){ | |
85 | + $temp = explode($separador,$buffer); | |
86 | + if(count($temp) == $ncolunas){ | |
87 | + $linhas[] = $temp; | |
88 | + } | |
89 | + else{ | |
90 | + echo "<p class='paragrafo' >A linha abaixo apresentou um erro - número de colunas não bate com o cabeçalho</p>"; | |
91 | + var_dump($temp); | |
92 | + exit; | |
93 | + } | |
94 | + } | |
85 | 95 | } |
86 | 96 | } |
87 | 97 | fclose ($handle); |
88 | 98 | //decobre o tipo de coluna |
89 | - $testar = 10; | |
99 | + $testar = 50; | |
90 | 100 | if(count($linhas) < $testar){ |
91 | 101 | $testar = count($linhas); |
92 | 102 | } |
... | ... | @@ -112,7 +122,7 @@ if (ob_get_level() == 0) ob_start(); |
112 | 122 | try { |
113 | 123 | $dbh = new PDO('pgsql:dbname='.$conexao["bancodedados"].';user='.$conexao["usuario"].';password='.$conexao["senha"].';host='.$conexao["host"].';port='.$conexao["porta"]); |
114 | 124 | } catch (PDOException $e) { |
115 | - echo 'Connection failed: ' . $e->getMessage(); | |
125 | + echo 'Connection failed: ' . " "; | |
116 | 126 | } |
117 | 127 | //encoding do banco de dados |
118 | 128 | $sql = "SELECT pg_encoding_to_char(encoding) FROM pg_database WHERE datname = '".$conexao["bancodedados"]."'"; |
... | ... | @@ -126,6 +136,8 @@ if (ob_get_level() == 0) ob_start(); |
126 | 136 | if($encodingdb == "LATIN1"){ |
127 | 137 | $encodingdb = "ISO-8859-1"; |
128 | 138 | } |
139 | + echo "<p class='paragrafo' >Codificação do banco: <b>".$encodingdb."</b></p>"; | |
140 | + | |
129 | 141 | //gera o script para criar a tabela e verifica se ja existe |
130 | 142 | $sql = "SELECT table_name FROM information_schema.tables where table_schema = '".$_POST["i3GEOuploadcsvesquema"]."' AND table_name = '".$_POST["tabelaDestinocsv"]."'"; |
131 | 143 | $res = $dbh->query($sql,PDO::FETCH_ASSOC); |
... | ... | @@ -149,6 +161,11 @@ if (ob_get_level() == 0) ob_start(); |
149 | 161 | $sql .= implode(",",$temp).") WITH(OIDS=FALSE)"; |
150 | 162 | $sqltabela[] = $sql; |
151 | 163 | $sqltabela[] = "ALTER TABLE ".$_POST["i3GEOuploadcsvesquema"].".".$_POST["tabelaDestinocsv"]." OWNER TO ".$conexao["usuario"]; |
164 | + if(!empty($_POST["comentarioCsv"])){ | |
165 | + $enc = mb_detect_encoding($texto); | |
166 | + $_POST["comentarioCsv"] = mb_convert_encoding($_POST["comentarioCsv"],$encodingdb,$enc); | |
167 | + $sqltabela[] = "COMMENT ON TABLE ".$_POST["i3GEOuploadcsvesquema"].".".$_POST["tabelaDestinocsv"]." IS '".addcslashes($_POST["comentarioCsv"])."'"; | |
168 | + } | |
152 | 169 | echo "<br>Sql tabela: <pre>"; |
153 | 170 | var_dump($sqltabela); |
154 | 171 | echo "</pre>"; |
... | ... | @@ -178,29 +195,39 @@ if (ob_get_level() == 0) ob_start(); |
178 | 195 | $nlinhas = count($linhas); |
179 | 196 | $valorX = 0; |
180 | 197 | $valorY = 0; |
198 | + $escapar = "',<,>,%,#,@,(,)"; | |
181 | 199 | for ($i=0; $i<$nlinhas;$i++){ |
182 | 200 | $s = $linhas[$i]; |
201 | + $s = str_replace('"','',$s); | |
202 | + $enc = mb_detect_encoding($s); | |
203 | + if($enc != ""){ | |
204 | + $s = mb_convert_encoding($s,$encodingdb,$enc); | |
205 | + } | |
183 | 206 | $vs = array(); |
184 | 207 | for ($j=0; $j<$ncolunas;$j++){ |
185 | - if($tipoColuna[$colunas[$j]] == "varchar"){ | |
208 | + $escape = ""; | |
209 | + if($tipoColuna[$coluna] == "varchar"){ | |
186 | 210 | $texto = $s[$j]; |
187 | - $texto = str_replace("'","",$texto); | |
188 | 211 | $enc = mb_detect_encoding($texto); |
189 | - if(enc != ""){ | |
190 | - $texto = "'".mb_convert_encoding($texto,$encodingdb,$enc)."'"; | |
212 | + $textosl = addcslashes($texto,$escapar); | |
213 | + if($textosl != $texto){ | |
214 | + $escape = "E"; | |
215 | + } | |
216 | + if($enc != "" && $enc != $encodingdb){ | |
217 | + $textosl = "$escape'".mb_convert_encoding($textosl,$encodingdb,$enc)."'"; | |
191 | 218 | } |
192 | 219 | else{ |
193 | - $texto = "'".$texto."'"; | |
220 | + $textosl = "$escape'".$textosl."'"; | |
194 | 221 | } |
195 | - if($texto == "''"){ | |
196 | - $texto = 'null'; | |
222 | + if($textosl == "''"){ | |
223 | + $textosl = 'null'; | |
197 | 224 | } |
198 | - $vs[] = $texto; | |
225 | + $vs[] = $textosl; | |
199 | 226 | } |
200 | 227 | else{ |
201 | 228 | $valor = $s[$j]; |
202 | - if($valor == ""){ | |
203 | - $valor = "nulo"; | |
229 | + if($valor == "" || (empty($valor) && $valor != 0)){ | |
230 | + $valor = 'nulo'; | |
204 | 231 | } |
205 | 232 | $vs[] = $valor; |
206 | 233 | } |
... | ... | @@ -234,23 +261,42 @@ if (ob_get_level() == 0) ob_start(); |
234 | 261 | try { |
235 | 262 | $dbh->query($linha); |
236 | 263 | } catch (PDOException $e) { |
237 | - echo 'Erro: ' . $e->getMessage(); | |
264 | + echo 'Erro: ' . " "; | |
238 | 265 | } |
239 | 266 | } |
267 | + $bdcon = pg_connect('dbname='.$conexao["bancodedados"].' user='.$conexao["usuario"].' password='.$conexao["senha"].' host='.$conexao["host"].' port='.$conexao["porta"]."options='-c client_encoding=LATIN1'"); | |
268 | + | |
240 | 269 | foreach($linhasql as $linha){ |
241 | 270 | try { |
242 | 271 | $res = $dbh->query($linha); |
243 | 272 | if($res == false){ |
244 | - echo "<br><br><span style=color:red >Erro em: </span>".$linha; | |
273 | + $res = pg_query($bdcon,$linha); | |
274 | + if($res == false){ | |
275 | + $linha = remove_accents($linha); | |
276 | + $res = $dbh->query($linha); | |
277 | + if($res == false){ | |
278 | + $res = pg_query($bdcon,$linha); | |
279 | + if($res == false){ | |
280 | + echo "<br><br><span style=color:red >Erro em: </span>".$linha; | |
281 | + } | |
282 | + } | |
283 | + else{ | |
284 | + echo "<br><br><span style=color:red >Linha com acentos removidos: </span>".$linha; | |
285 | + } | |
286 | + } | |
245 | 287 | } |
246 | 288 | } catch (PDOException $e) { |
247 | - echo 'Erro: ' . $e->getMessage(); | |
289 | + echo 'Erro: ' . " "; | |
248 | 290 | } |
249 | 291 | } |
250 | - echo "<br>Registros existentes no CSV: ". $nlinhas; | |
251 | 292 | $sql = "select * from ".$_POST["i3GEOuploadcsvesquema"].".".$_POST["tabelaDestinocsv"]; |
252 | 293 | $q = $dbh->query($sql,PDO::FETCH_ASSOC); |
253 | 294 | $r = $q->fetchAll(); |
295 | + if($nlinhas != count($r)){ | |
296 | + echo "<span style='color:red'>"; | |
297 | + } | |
298 | + echo "<br>Registros existentes no CSV: ". $nlinhas; | |
299 | + | |
254 | 300 | echo "<br>Registros na tabela final: ". count($r); |
255 | 301 | echo "<b><br>Feito!!!<br>Faça o reload da página"; |
256 | 302 | } |
... | ... | @@ -258,8 +304,8 @@ if (ob_get_level() == 0) ob_start(); |
258 | 304 | echo "<p class='paragrafo' >Erro ao enviar o arquivo. Talvez o tamanho do arquivo seja maior do que o permitido.</p>"; |
259 | 305 | } |
260 | 306 | |
261 | - ?> | |
262 | - <script>window.scrollTo(0,10000);</script> | |
307 | + ?> | |
308 | + <script>window.scrollTo(0,10000);</script> | |
263 | 309 | |
264 | 310 | </body> |
265 | 311 | </html> | ... | ... |
admin/php/metaestat_uploaddados_submit.php
... | ... | @@ -7,7 +7,7 @@ if (isset($_FILES['i3GEOuploadArquivo']['name'])) |
7 | 7 | { |
8 | 8 | require_once (dirname(__FILE__)."/../../ms_configura.php"); |
9 | 9 | $Arquivoup = $_FILES['i3GEOuploadArquivo']['tmp_name']; |
10 | - $nomearquivoserv = $dir_tmp."/upload".basename($Arquivoup); | |
10 | + $nomearquivoserv = $dir_tmp."/upload".basename($Arquivoup).".csv"; | |
11 | 11 | //echo $nomearquivoserv; |
12 | 12 | if(file_exists($nomearquivoserv)){ |
13 | 13 | unlink($nomearquivoserv); | ... | ... |
admin/php/uploadgvp.php
... | ... | @@ -9,6 +9,7 @@ if (ob_get_level() == 0) ob_start(); |
9 | 9 | ?> |
10 | 10 | <html> |
11 | 11 | <head> |
12 | +<link rel="stylesheet" type="text/css" href="../../css/input.css" /> | |
12 | 13 | <link rel="stylesheet" type="text/css" href="../../css/geral.css" /> |
13 | 14 | <title></title> |
14 | 15 | </head> |
... | ... | @@ -21,9 +22,10 @@ if (isset($_FILES['i3GEOuploadgvp']['name'])){ |
21 | 22 | ob_flush(); |
22 | 23 | flush(); |
23 | 24 | sleep(1); |
24 | - $arq = $locaplic."/temas/".$_FILES['i3GEOuploadgvp']['name']; | |
25 | - //verifica nomes | |
26 | 25 | verificaNome($_FILES['i3GEOuploadgvp']['name']); |
26 | + $ArquivoDest = $_FILES['i3GEOuploadgvp']['name']; | |
27 | + $ArquivoDest = str_replace(".gvp","",$ArquivoDest).".gvp"; | |
28 | + $arq = $locaplic."/temas/".$ArquivoDest; | |
27 | 29 | if(file_exists($arq)){ |
28 | 30 | unlink($arq); |
29 | 31 | } | ... | ... |