-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreceberForm.php
More file actions
72 lines (51 loc) · 2.19 KB
/
receberForm.php
File metadata and controls
72 lines (51 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
function apache_request_headers() {
$arh = array();
$rx_http = '/\AHTTP_/';
foreach($_SERVER as $key => $val) {
if( preg_match($rx_http, $key) ) {
$arh_key = preg_replace($rx_http, '', $key);
$rx_matches = array();
// do some nasty string manipulations to restore the original letter case
// this should work in most cases
$rx_matches = explode('_', $arh_key);
if( count($rx_matches) > 0 and strlen($arh_key) > 2 ) {
foreach($rx_matches as $ak_key => $ak_val) $rx_matches[$ak_key] = ucfirst($ak_val);
$arh_key = implode('-', $rx_matches);
}
$arh[$arh_key] = $val;
}
}
return( $arh );
}
require_once 'includes/configxml.php';
try
{
$mongo = new MongoClient(); // connect
$dbMongo = $mongo->selectDB("local");
} catch (Exception $e) {
$sql = 'insert into log(error_msg) values ("erro de conexao")';
$db->query($sql);
}
foreach($_FILES as $file) {
move_uploaded_file($file["tmp_name"], "formularios/" . $file['name']);
$sql = 'insert into pesquisa_recebida(aparelho) values ("' . $file['name'] . '")';
$db->query($sql);
/* Vou tentar converter pra JSON e inserir no MongoDB, se der errado gravarei o nome do arquivo em um log
no MYSQL */
$ext = pathinfo($file['name']);
if('xml' == $ext['extension']) {
$conteudoXML = simplexml_load_string(file_get_contents("formularios/" . $file['name'] ));
// $jsonConteudo = json_encode($conteudoXML);
try {
$colecao = $dbMongo->familias;
// $colecao->insert(json_decode($jsonConteudo));
$colecao->insert($conteudoXML);
} catch (Exception $e) {
$sql = 'insert into log(error_msg) values ("erro de conversao")';
$db->query($sql);
}
}
}
header("Status: 201");
?>