I want to check file types on server using php. Now I have confirmed this by checking the type of file extension. This works fines, but the problem is that this is not the best way to check the file as a user, the change allows you to say the text file in jpeg and still be able to upload it.
So I want to add another validation method, I also want to check the MIME file type with php to find out if the file is an image, video or audio.
So my question is how is it encoded so that I can use the MIME type in php to check the file? Also, if I have an extremely large file, does it take a long time to check MIME or check it right away?
Below is the code that I only have for the image where it uses PHP code to check the file type:
<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
}
}
else
{
echo "Invalid file";
}
?>
source
share