-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidateFileType.php
More file actions
39 lines (30 loc) · 891 Bytes
/
validateFileType.php
File metadata and controls
39 lines (30 loc) · 891 Bytes
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
<?php
/**
* @author : rofi
* @desc file type validation function
* @param allowed array contains all allowed extensions list .validateFileType
* file name is the file name.validateFileType
* <example:>
* $allowed = array('jpg', 'png', 'jpeg');
* $filename = $_FILES['file']['name'];
* validateFileType($allowed, $filename);
* </example:>
*/
function validateFileType($allowed, $filename){
//take the extension of the file
$ext = pathinfo($filename, PATHINFO_EXTENSION);
//return the result
if (in_array($ext, $allowed)) {
$result = [
"status" => "true",
"msg" => "file validated",
];
} else {
$result = [
"status" => "false",
"msg" => "file not valid",
];
}
//return the message array
return $result;
}