-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVerifyImage.php
More file actions
30 lines (23 loc) · 814 Bytes
/
VerifyImage.php
File metadata and controls
30 lines (23 loc) · 814 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
<?php
function VerifyImage(string $inputName){
$file = $_FILES[$inputName];
if($file["error"]) {
throw new Exception("Error: ". $file["error"]);
}
$config = array(
"maxSize"=>20000000,
"extensions"=>array('png', 'jpeg', 'jpg')
);
$file["extension"] = pathinfo($file["name"], PATHINFO_EXTENSION);
$file["extension_index"] = array_search($file["extension"], $config["extensions"]);
if(!in_array($file["extension"], $config["extensions"])) {
throw new Exception("Formato inválido! A imagem deve ser jpg, jpeg ou png.");
}
else {
if($file["size"] > $config["maxSize"]) {
throw new Exception("Erro: A imagem deve ser de no máximo " . $config["maxSize"] . " bytes.");
}
}
return $file;
}
?>