Skip to content
Advertisement

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

I have following script:

function listFolderFiles($dir){
    $ffs = scandir($dir);
    echo '<ol>';
    foreach($ffs as $ff){
        if($ff != '.' && $ff != '..'){
            echo '<li>'.$ff;
            if(is_dir($dir.'/'.$ff)) listFolderFiles($dir.'/'.$ff);
            echo '</li>';
        }
    }
    echo '</ol>';
}
listFolderFiles('upload');

My question is I want to detect a file is video(mp4 or mov)type, How i can detect $ff is a video type or not?

Advertisement

Answer

if(end(explode(".",$ff)) =="mp4")
{
echo "its an mp4 movie";
}

There you go, for case insensitive version of the extension

<?php
$ff="abc.MP4";
if(strtolower(end(explode(".",$ff))) =="mp4")
{
echo "its an mp4 movie";
}
?>
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement