FileFunction   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 41
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getFileMimeType() 0 9 2
A getTmpFile() 0 5 1
A deleteTmpFile() 0 3 1
1
<?php
2
// +----------------------------------------------------------------------
3
// | date: 2016-11-13
4
// +----------------------------------------------------------------------
5
// | UtilityLibrary.php: 工具库
6
// +----------------------------------------------------------------------
7
// | Author: yangyifan <[email protected]>
8
// +----------------------------------------------------------------------
9
namespace tinymeng\uploads\Helper;
10
class FileFunction
11
{
12
    /**
13
     * 获得文件mime_type
14
     *
15
     * @param $file
16
     * @return bool|mixed
17
     * @author yangyifan <[email protected]>
18
     */
19
    public static function getFileMimeType($file)
20
    {
21
        $finfo = finfo_open(FILEINFO_MIME_TYPE);
22
        if ($finfo) {
0 ignored issues
show
introduced by
$finfo is of type resource, thus it always evaluated to false.
Loading history...
23
            $mime_type = finfo_file($finfo, $file);
24
            finfo_close($finfo);
25
            return $mime_type;
26
        }
27
        return false;
28
    }
29
    /**
30
     * 获得一个临时文件
31
     *
32
     * @return string
33
     * @author yangyifan <[email protected]>
34
     */
35
    public static function getTmpFile()
36
    {
37
        $tmpfname       = tempnam("/tmp", "dir");
38
        chmod($tmpfname, 0777);
39
        return $tmpfname;
40
    }
41
    /**
42
     * 删除一个临时文件
43
     *
44
     * @param $file_name
45
     * @return bool
46
     * @author yangyifan <[email protected]>
47
     */
48
    public static function deleteTmpFile($file_name)
49
    {
50
        return unlink($file_name);
51
    }
52
}