Skip to content

Commit a06b7ad

Browse files
authored
Add files via upload
1 parent ae590b4 commit a06b7ad

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

file-uploader.php

+4-7
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,17 @@ function upload ($file = null, $uploadFolder = null) : string {
3838
$fileName = trim($file["name"], "./\\");
3939

4040
// Extract file extension from file name
41-
$fileExtension = pathinfo($fileName, PATHINFO_EXTENSION);
41+
$fileExtension = strtoupper(pathinfo($fileName, PATHINFO_EXTENSION));
4242

4343
// Define list of allowed file extensions.
4444
// You can modify this list by add more extensions or remove existing extensions.
4545
// TODO : Make $EXTENSIONS_ALLOWED variable a constant?
4646
$EXTENSIONS_ALLOWED = ["PNG", "JPG", "JPEG", "PDF"];
4747

4848
// Ensure the file estension is allowed
49-
foreach ($EXTENSIONS_ALLOWED as $allowed_file_extension) {
50-
// Compare two extensions, disregarding their cases
51-
if (strcasecmp($allowed_file_extension, $fileExtension) !== 0) {
52-
// File extension not allowed
53-
return "";
54-
}
49+
if (!in_array($fileExtension, $EXTENSIONS_ALLOWED, false)) {
50+
// File extension not allowed
51+
return "";
5552
}
5653

5754
// Get file size (Given in Bytes)

0 commit comments

Comments
 (0)