-
Notifications
You must be signed in to change notification settings - Fork 0
/
submit_form.php
84 lines (80 loc) · 2.73 KB
/
submit_form.php
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
73
74
75
76
77
78
79
80
81
82
83
84
<?php
$uploaddir = './formularios/';
if ($_POST){
if (!is_dir($uploaddir)){
if (!mkdir($uploaddir, 0777, true)) {
die('Failed to create folders...');
}
}
// echo ('<br>POST<br>');
// var_dump(json_encode($_POST));
$uploaddir .= '/' . $_POST['form_id'] . '/';
if (strlen($_POST['nome']) > 0){
$uploaddir .= str_replace(' ','_',$_POST['nome']) . '_';
}
$uploaddir .= substr(str_replace(':','.', date(DATE_ATOM)), 0, -6);
if (!is_dir($uploaddir)){
if (!mkdir($uploaddir, 0777, true)) {
die('Failed to create folders...');
}
}
$formfile = $uploaddir . '/form.json';
file_put_contents($formfile, json_encode($_POST));
$formfile = $uploaddir . '/dados.txt';
$dados = "";
$longest_key = 0;
foreach($_POST as $key => $value){ $longest_key = max(strlen($key), $longest_key); }
foreach($_POST as $key => $value){
$space = "";
for ($i = 0; $i< $longest_key - strlen($key); $i++){ $space .= ' ';}
$dados .= "$key:$space $value\n";
}
file_put_contents($formfile, $dados);
if ($_FILES){
// echo ('<br><br>FILES<br>');
// var_dump($_FILES);
foreach($_FILES as $fieldname => $value){
if ($value["error"] > 0){
// echo ("Error: " . $value["error"] . "<br />");
}
// var_dump($fieldname);
// echo '<br><br>';
// var_dump($value);
// echo '<br><br>';
$dir = $uploaddir . '/' . $fieldname;
if (!is_dir($dir)){
if (!mkdir($dir, 0777, true)) {
die('Failed to create folders...');
}
}
if(strlen($value['name']) > 1){
$uploadfile = $dir . '/' . basename($value['name']);
if(basename($value['name']) == '.htaccess'){
die('NOPE');
}
if (move_uploaded_file($value['tmp_name'], $uploadfile)) {
// echo "File is valid, and was successfully uploaded.\n";
// $htaccess = "php_flag engine off\nIndexIgnore *";
// file_put_contents($dir . '/.htaccess', $htaccess);
} else {
die("Possible file upload attack!\n");
}
} else{
// echo("Missing file: $fieldname");
}
}
}
if (strlen($_POST['notificar_email']) > 3){
$recipient = $_POST['notificar_email'];
$url = 'http://calendariocultural.com.br' . str_replace('//','/',substr($uploaddir,1));
$body = "== Novo formulário submetido ==\n\n$dados";
$body .= "\nAcesse os arquivos submetidos clicando pela URL abaixo:\n$url";
$subject = "[calendariocultural] Novo formulário: " . $_POST['nome'];
$sender = '[email protected]';
$headers = "From: $sender \r\n" .
'X-Mailer: PHP/' . phpversion();
mail($recipient, $subject, $body, $headers);
}
echo "success";
}
?>