From 45035ebf360da920d5212315f87a66be85e4d00f Mon Sep 17 00:00:00 2001 From: Daniel Winzen Date: Sun, 27 Dec 2020 16:43:37 +0100 Subject: [PATCH] Use mime_content_type to determin uploaded files mime type when available --- chat.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/chat.php b/chat.php index d5eb562..d65ece7 100644 --- a/chat.php +++ b/chat.php @@ -3042,10 +3042,12 @@ function validate_input() : string { $stmt->execute([$newmessage['postdate'], $id[0], $newmessage['poster'], $newmessage['recipient'], $newmessage['text']]); } if(isset($hash) && $id){ - if(!empty($_FILES['file']['type']) && preg_match('~^[a-z0-9/\-.+]*$~i', $_FILES['file']['type'])){ - $type=$_FILES['file']['type']; + if(function_exists('mime_content_type')){ + $type = mime_content_type($_FILES['file']['tmp_name']); + }elseif(!empty($_FILES['file']['type']) && preg_match('~^[a-z0-9/\-.+]*$~i', $_FILES['file']['type'])){ + $type = $_FILES['file']['type']; }else{ - $type='application/octet-stream'; + $type = 'application/octet-stream'; } $stmt=$db->prepare('INSERT INTO ' . PREFIX . 'files (postid, hash, filename, type, data) VALUES (?, ?, ?, ?, ?);'); $stmt->execute([$id[0], $hash, str_replace('"', '\"', $_FILES['file']['name']), $type, base64_encode(file_get_contents($_FILES['file']['tmp_name']))]);