-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathFileExt.php
More file actions
83 lines (67 loc) · 1.34 KB
/
FileExt.php
File metadata and controls
83 lines (67 loc) · 1.34 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
namespace Utopia\Storage\Validator;
use Utopia\Http\Validator;
class FileExt extends Validator
{
const TYPE_JPEG = 'jpeg';
const TYPE_JPG = 'jpg';
const TYPE_GIF = 'gif';
const TYPE_PNG = 'png';
const TYPE_GZIP = 'gz';
const TYPE_ZIP = 'zip';
/**
* @var array
*/
protected $allowed;
/**
* @param array $allowed
*/
public function __construct(array $allowed)
{
$this->allowed = $allowed;
}
/**
* Get Description
*/
public function getDescription(): string
{
return 'File extension is not valid';
}
/**
* Check if file extenstion is allowed
*
* @param mixed $filename
* @return bool
*/
public function isValid($filename): bool
{
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$ext = strtolower($ext);
if (! in_array($ext, $this->allowed)) {
return false;
}
return true;
}
/**
* Is array
*
* Function will return true if object is array.
*
* @return bool
*/
public function isArray(): bool
{
return false;
}
/**
* Get Type
*
* Returns validator type.
*
* @return string
*/
public function getType(): string
{
return self::TYPE_STRING;
}
}