summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAustin <austi_gillm935@ahapps.anoka.k12.mn.us>2016-06-21 15:29:43 +0200
committerGitHub <noreply@github.com>2016-06-21 15:29:43 +0200
commit0d7028c01d85405fe441bdc0cc7448bb59a9cf19 (patch)
tree0a3046f1b01c5c3a85a0f4144134237600791a4c
parent342c0128119367392072760ef14a1a5f4443e905 (diff)
parente01670d1bb7204051e076069f50fd68d55e8c92c (diff)
Merge pull request #18 from akpu1/patch-1
Have FILTER_MODE determine whether FILTER_MIME is white/blacklist
-rw-r--r--php/includes/settings.inc.php12
-rw-r--r--php/upload.php15
2 files changed, 13 insertions, 14 deletions
diff --git a/php/includes/settings.inc.php b/php/includes/settings.inc.php
index 19a3987..6e70569 100644
--- a/php/includes/settings.inc.php
+++ b/php/includes/settings.inc.php
@@ -90,17 +90,15 @@ define('ID_CHARSET', 'abcdefghijklmnopqrstuvwxyz');
/**
- * Blocked mime types
- * @param string[] $FILTER_MIME blocked mime types
+ * Filtered mime types
+ * @param string[] $FILTER_MIME allowed/blocked mime types
*/
$FILTER_MIME = array("");
-
/**
- * Whitelisted mime types
- * @param string[] $WHITELIST_MIME_MIME allowed mime types
+ * Filter mode: whitelist (true) or blacklist (false)
+ * @param bool $FILTER_MODE mime type filter mode
*/
-$WHITELIST_MIME = array("");
-
+$FILTER_MODE = false;
/**
* Double dot file extensions
*
diff --git a/php/upload.php b/php/upload.php
index b9e5f55..d63ee5e 100644
--- a/php/upload.php
+++ b/php/upload.php
@@ -75,7 +75,7 @@ function generateName($file)
function uploadFile($file)
{
global $db;
- global $WHITELIST_MIME;
+ global $FILTER_MODE;
global $FILTER_MIME;
// Handle file errors
@@ -85,13 +85,14 @@ function uploadFile($file)
// Check if mime type is blocked
if (!empty($FILTER_MIME)) {
- if (in_array($file->mime, $FILTER_MIME)) {
- throw new UploadException(UPLOAD_ERR_EXTENSION);
- }
- }
- if (!empty($WHITELIST_MIME)) {
- if (!in_array($file->mime, $WHITELIST_MIME)) {
+ if ($FILTER_MODE == true) { //whitelist mode
+ if (!in_array($file->mime, $FILTER_MIME)) {
+ throw new UploadException(UPLOAD_ERR_EXTENSION);
+ }
+ } else { //blacklist mode
+ if (in_array($file->mime, $FILTER_MIME)) {
throw new UploadException(UPLOAD_ERR_EXTENSION);
+ }
}
}