From a3952f82e3871f50d3e547dd1a5972a736ae2503 Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Tue, 28 Oct 2014 10:46:29 -0500 Subject: [PATCH] files: Avoid crash if `fileinfo` extension missing --- include/class.file.php | 6 +++--- include/staff/system.inc.php | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/include/class.file.php b/include/class.file.php index 15f4ea17a..b38ddb2dc 100644 --- a/include/class.file.php +++ b/include/class.file.php @@ -331,7 +331,7 @@ class AttachmentFile { return false; } - if (!$file['type']) { + if (!$file['type'] && extension_loaded('fileinfo')) { $finfo = new finfo(FILEINFO_MIME_TYPE); if ($file['data']) $type = $finfo->buffer($file['data']); @@ -340,9 +340,9 @@ class AttachmentFile { if ($type) $file['type'] = $type; - else - $file['type'] = 'application/octet-stream'; } + if (!$file['type']) + $file['type'] = 'application/octet-stream'; $sql='INSERT INTO '.FILE_TABLE.' SET created=NOW() ' .',type='.db_input(strtolower($file['type'])) diff --git a/include/staff/system.inc.php b/include/staff/system.inc.php index 4238e3dbe..1445f2547 100644 --- a/include/staff/system.inc.php +++ b/include/staff/system.inc.php @@ -33,6 +33,10 @@ $extensions = array( 'name' => 'phar', 'desc' => __('Highly recommended for plugins and language packs') ), + 'fileinfo' => array( + 'name' => 'fileinfo', + 'desc' => __('Used to detect file types for uploads') + ), ); ?> -- GitLab