Computer >> Computer tutorials >  >> Programming >> PHP

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


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.