Validating the file field
PHP move_uploaded_file function is used to upload the file by accessing file data stored in $_FILES superglobal.
If you are looking for a django "File Field" to use in your model with MAX_UPLOAD_SIZE and CONTENT_TYPE restrictions this post is for you.
What if instead of return a boolean, we return an error message? But, what if the user input fails in more than one time at the same time?
File upload feature requires basic validations to sanitize the user input.
Like working with plain text inputs, to upload a single file you would create a model class and use an attribute of the model to keep the uploaded file instance.
You should also declare a validation rule to validate the file upload. We then rely on the model validation to make sure the uploaded file is valid and save the file on the server.