How to Validate the File Type of a File Using Python (Simple)

preview_player
Показать описание
How to Validate the File Type of a File Using Python (Simple)

Greetings, today we are going to be looking at how we can validate the file type of a file using Python. This is a simple method but is not bulletproof. If someone wants to upload an invalid file type, they can. This is more useful to stop accidental uploads or inform users who made a mistake with uploading a file.

This tutorial will not cover how to upload a file, just how to validate the file type using the name of the file. We can check the extension to determine the file type with some simple string manipulation.

I also include how to check if a file exists incase that is something you also want. Thanks for watching this tutorial on how to Validate a file type using Python.

How to Validate the File Type of a File Using Python (Simple)
Рекомендации по теме
Комментарии
Автор

I would check if the file name ends with "." + extension instead, some files might have dots in the name.

orbyfied
Автор

What happened when we renamed .jpg file to .png file it will validate? And what I need to only the validate the real .png file extension not renamed?

Lucifer-djtm