summaryrefslogtreecommitdiff
path: root/app/php/components/SafeFileUpload.php
blob: 98e120aa263136299f6045121bb887c53225e48b (plain)
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
<?php

class SafeFileUpload extends TFileUpload {

    use MimeTypeCheckForFileUpload;

}

trait MimeTypeCheckForFileUpload {

    protected $_isSecure = TRUE;

    public function getIsSecure() {
        return $this->_isSecure;
    }

    public function setIsSecure($bool) {
        $this->_isSecure = $bool;
    }

    public function getFileType() {
        $type = parent::getFileType();
        if ($this->getIsSecure()) {
            $fileInfo = new finfo(FILEINFO_MIME_TYPE);
            return $fileInfo->file($this->getLocalName());
        }
        else {
            return $type;
        }
    }

}

?>