Classi per la configurazione upload
Cristiano Magro
2019-07-09 d69fe7b1a85ee19a9288f9bd77e727a1c82bfa4f
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
<?php
/**
 * User: Cristiano Magro
 * Date: 08/07/2019
 */
 
class FilesFilter
{
 
    private $filtro = array();
 
    public function toJson()
    {
        return json_encode($this->filtro);
    }
 
    public function addExt($extension = '')
    {
        if ($extension != ''){
            switch(strtolower($extension)) {
                case 'gif':
                    $this->filtro[] = json_decode('{"title":"Image files", "extensions":"gif"}', true);
                    break;
                case 'doc':
                    $this->filtro[] = json_decode('{"title":"Documenti", "extensions":"doc"}', true);
                    break;
            }
        }
        return $this;
    }
 
    /**
     * Decodifico il titolo in base all'estensione.
     * Il confronto viene eseguito in lowercase
     * @param string $ext
     * @return string
     */
    public function decodeTitolo($ext)
    {
        switch (strtolower($ext)) {
            case 'gif':
                $titolo = "Image files";
                break;
            case 'doc':
            case 'txt':
                $titolo = "Documenti";
                break;
        }
 
        return $titolo;
    }
 
}