-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommon.php
86 lines (82 loc) · 2.44 KB
/
Common.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
85
86
<?php
$meses = [
1 => 'Janeiro', 'Fevereiro', 'Março',
'Abril', 'Maio', 'Junho',
'Julho', 'Agosto', 'Setembro',
'Outubro', 'Novembro', 'Dezembro'
];
$mesesCurto = [
1 => 'Jan', 'Fev', 'Mar',
'Abr', 'Mai', 'Jun',
'Jul', 'Ago', 'Set',
'Out', 'Nov', 'Dez'
];
$diaSemana = [
'Domingo', 'Segunda-Feira', 'Terça-Feira', 'Quarta-Feira',
'Quinta-Feira', 'Sexta-Feira', 'Sábado'
];
$diaSemanaCurto = [
'Dom', 'Seg', 'Ter', 'Qua',
'Qui', 'Sex', 'Sáb'
];
$now = time();
$date = [
'dia' => date('d', $now),
'mes' => date('n', $now),
'ano' => date('Y', $now),
'diaSemana' => date('w', $now)
];
$hojeExt = "{$diaSemana[$date['diaSemana']]}, {$date['dia']} de {$meses[$date['mes']]} de {$date['ano']}";
$hoje = date('d/m/Y', $now);
/**
* Listar um diretorio
*
* @param string $path Caminho para listar
* @param array of string $excludes Nomes excluidos da lista
* @param int $type Tipo de arquivos (0 - Pastas / 1 - Arquivos / 2 - Ambos)
* @return array of string Lista de arquivos/pastas
* */
function listDir ($path, $excludes = [], $type = 0)
{
$excludes[] = '.';
$excludes[] = '..';
if (is_dir($path)) {
if ($handle = opendir($path)) {
$data = [];
while (false !== ($entry = readdir($handle))) {
if (substr($entry, 0, 1) != '.' && !in_array($entry, $excludes)) {
if ($type == 2 || ($type == 0 && is_dir($path.$entry)) || ($type == 1 && is_file($path.$entry))) {
$data[] = $entry;
}
}
}
closedir($handle);
return $data;
}
}
return [];
}
function deleteFile ($filename) {
$filename = str_replace('/', '', $filename);
if (!in_array(substr($filename,0,1),['.','~'])) {
$filename = realpath('./download'). DIRECTORY_SEPARATOR . $filename;
if (is_file($filename)) {
unlink($filename);
}
}
}
function uploadFile () {
foreach ($_FILES["arquivo"]["error"] as $i => $error) {
if ($error == UPLOAD_ERR_OK) {
$filename = realpath('./download'). DIRECTORY_SEPARATOR . $_FILES['arquivo']['name'][$i];
if (is_file($filename)) {
unlink($filename);
}
if (move_uploaded_file($_FILES['arquivo']['tmp_name'][$i], $filename)) {
chmod($filename, 0666);
} else {
echo '<p>Erro ao enviar arquivo</p>';
}
}
}
}