Added a function to check posted files

This commit is contained in:
Pierre 2018-01-06 18:25:27 +01:00
parent 8cbacb2746
commit e4343b0ef4

View File

@ -210,4 +210,28 @@ function getPostPostID(string $name = "postID") : int {
Rest_fatal_error(404, "Specified post does not exists!"); Rest_fatal_error(404, "Specified post does not exists!");
return $postID; 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;
} }