1 | <?php |
||
5 | class UploadFile extends AbstractValidator |
||
6 | { |
||
7 | const NO_LIMIT_SIZE = 0; |
||
8 | const ALL_TYPE = []; |
||
9 | |||
10 | /** |
||
11 | * Error code : PHP upload error code. |
||
12 | */ |
||
13 | const PHP_INI_SIZE = 'ini_size'; |
||
14 | const PHP_FORM_SIZE = 'form_size'; |
||
15 | const PHP_PARTIAL = 'partial'; |
||
16 | const PHP_NO_FILE = 'no_file'; |
||
17 | const PHP_NO_TMP_DIR = 'no_tmp_dir'; |
||
18 | const PHP_CANT_WRITE = 'cant_write'; |
||
19 | const PHP_EXTENSION = 'err_extension'; |
||
20 | |||
21 | /** |
||
22 | * Error code : Unknown error |
||
23 | */ |
||
24 | const NO_UPLOADED_FILE = 'no_uploaded_file'; |
||
25 | |||
26 | /** |
||
27 | * Error code : Not valid type |
||
28 | */ |
||
29 | const NOT_VALID_TYPE = 'not_valid_type'; |
||
30 | |||
31 | const LARGE_SIZE = 'large_size'; |
||
32 | |||
33 | /** |
||
34 | * Error messages |
||
35 | * |
||
36 | * @var array |
||
37 | */ |
||
38 | protected $messages = [ |
||
39 | self::PHP_INI_SIZE => 'Uploaded file exceeds the defined PHP INI size.', |
||
40 | self::PHP_FORM_SIZE => 'Uploaded file exceeds the defined form size.', |
||
41 | self::PHP_PARTIAL => 'Uploaded file was only partially uploaded.', |
||
42 | self::PHP_NO_FILE => 'Uploaded file was not uploaded.', |
||
43 | self::PHP_NO_TMP_DIR => 'Missing a temporary folder.', |
||
44 | self::PHP_CANT_WRITE => 'Failed to write uploaded file to disk.', |
||
45 | self::PHP_EXTENSION => 'Uploaded file was stopped by extension.', |
||
46 | self::NO_UPLOADED_FILE => 'No uploaded file.', |
||
47 | self::NOT_VALID_TYPE => 'Uploaded file has not valid type.', |
||
48 | self::LARGE_SIZE => 'Uploaded file was too large.' |
||
49 | ]; |
||
50 | |||
51 | /** |
||
52 | * Size limit upload file, in byte. |
||
53 | * |
||
54 | * @param int $size |
||
55 | * |
||
56 | * @return $this |
||
57 | */ |
||
58 | public function hasMaxSize($size) |
||
64 | |||
65 | /** |
||
66 | * Set allow file type (image/gif, image/png ...) |
||
67 | * |
||
68 | * @param string $type |
||
69 | * |
||
70 | * @return $this |
||
71 | */ |
||
72 | public function allowType($type) |
||
78 | |||
79 | /** |
||
80 | * Validate. |
||
81 | * |
||
82 | * @param [] $value |
||
|
|||
83 | * |
||
84 | * @return boolean |
||
85 | */ |
||
86 | public function isValid($value) |
||
114 | |||
115 | /** |
||
116 | * Validate uploaded file. |
||
117 | * |
||
118 | * @param string $path |
||
119 | * @param int $error |
||
120 | * |
||
121 | * @return boolean |
||
122 | */ |
||
123 | protected function isValidUploadFile($path, $error) |
||
147 | |||
148 | /** |
||
149 | * Validate size of uploaded file. |
||
150 | * |
||
151 | * @param int $size |
||
152 | * |
||
153 | * @return boolean |
||
154 | */ |
||
155 | protected function isValidSize($size) |
||
168 | |||
169 | protected function isValidFileType($type) |
||
184 | |||
185 | /** |
||
186 | * Init. |
||
187 | * |
||
188 | * Set default options. |
||
189 | */ |
||
190 | protected function init() |
||
197 | |||
198 | /** |
||
199 | * Get file type |
||
200 | * |
||
201 | * TODO: move to new project |
||
202 | * |
||
203 | * @param string $file File path |
||
204 | * @return string |
||
205 | */ |
||
206 | protected function getFileType($file) |
||
213 | |||
214 | /** |
||
215 | * Get file extension |
||
216 | * |
||
217 | * TODO: move to new project |
||
218 | * |
||
219 | * @param string $file File name |
||
220 | * @return string |
||
221 | * |
||
222 | * |
||
223 | */ |
||
224 | protected function getFileExt($file) |
||
234 | } |
||
235 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.