how to check whether file is image or video type in php version 5.2.9
php $finfo = finfo_open(FILEINFO_MIME_TYPE); // return mime type ala mimetype extension foreach (glob("*") as $filename) { echo finfo_file($finfo, $filename) . "\n"; } finfo_close($finfo); ?> Save this answer. Show activity on this post.
Which file format is my video file? On Mac, right-click the video file and click “Get Info”, then under “More Info” you should see both the video and audio codec. On Windows, right-click the file and click “Properties”. Under the “Details” tab you will see the file format and codecs used.
In first method we have one built in function in PHP named as getimagesize(). Bu using this function we can check whether the image is valid or fake image file. In second method is done by curling the link or CURL, we can achieve this.
$mime = mime_content_type($file);
if(strstr($mime, "video/")){
// this code for video
}else if(strstr($mime, "image/")){
// this code for image
}
Should work for most file extentions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With