-
-
Notifications
You must be signed in to change notification settings - Fork 167
Expand file tree
/
Copy pathfileinfo.php
More file actions
56 lines (49 loc) · 1.07 KB
/
fileinfo.php
File metadata and controls
56 lines (49 loc) · 1.07 KB
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
<?php
namespace Safe;
use Safe\Exceptions\FileinfoException;
/**
* @param \finfo $finfo
* @return bool
*
*/
function finfo_close(\finfo $finfo): bool
{
error_clear_last();
$safeResult = \finfo_close($finfo);
return $safeResult;
}
/**
* @param int $flags
* @param null|string $magic_database
* @return \finfo
* @throws FileinfoException
*
*/
function finfo_open(int $flags = FILEINFO_NONE, ?string $magic_database = null): \finfo
{
error_clear_last();
if ($magic_database !== null) {
$safeResult = \finfo_open($flags, $magic_database);
} else {
$safeResult = \finfo_open($flags);
}
if ($safeResult === false) {
throw FileinfoException::createFromPhpError();
}
return $safeResult;
}
/**
* @param resource|string $filename
* @return string
* @throws FileinfoException
*
*/
function mime_content_type($filename): string
{
error_clear_last();
$safeResult = \mime_content_type($filename);
if ($safeResult === false) {
throw FileinfoException::createFromPhpError();
}
return $safeResult;
}