From e4343b0ef4e54e900e787f2c0827ad27bb41a587 Mon Sep 17 00:00:00 2001 From: Pierre Date: Sat, 6 Jan 2018 18:25:27 +0100 Subject: [PATCH] Added a function to check posted files --- functions/requests.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/functions/requests.php b/functions/requests.php index 4465056..a7d4e88 100644 --- a/functions/requests.php +++ b/functions/requests.php @@ -210,4 +210,28 @@ function getPostPostID(string $name = "postID") : int { Rest_fatal_error(404, "Specified post does not exists!"); return $postID; +} + +/** + * Check the validity of an file posted in a request + * + * @param string $name The name of the $_FILES entry + * @return bool True if the file is valid / false else + */ +function check_post_file(string $name) : bool { + + //Check if image exists + if(!isset($_FILES[$name])) + return false; + + //Check for errors + if($_FILES[$name]['error'] != 0) + return false; + + //Check if the file is empty + if($_FILES[$name]['size'] < 1) + return false; + + return true; + } \ No newline at end of file