FileFunction::getFileMimeType()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 9
rs 10
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
}