How to check a file is video type or not in php?

PHPServer Side ProgrammingProgramming

Let’s say the following is our variable wherein we have an .mp4 path file −

$movieFileType="demo.mp4";

To check whether the above file is video type, use end() along with explode(). You need to set this in strtolower() and check the condition −

if(strtolower(end(explode(".",$movieFileType))) =="mp4") {
}
else {
}

Example

<!DOCTYPE html>
<html>
<body>
<?php
$movieFileType="demo.mp4";
if(strtolower(end(explode(".",$movieFileType))) =="mp4") {
   echo "The movie ",$movieFileType," is of video type.";
} else {
   echo "The movie ",$movieFileType," is not of video type.";
}
?>
</body>
</html>

This will produce the following output −

Output

The movie demo.mp4 is of video type.
raja
Published on 12-Oct-2020 16:19:01
Advertisements