Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to check whether file is image or video type in php version 5.2.9?

Tags:

php

how to check whether file is image or video type in php version 5.2.9

like image 587
kirti kadam Avatar asked Jun 19 '10 05:06

kirti kadam


People also ask

How can I tell if file is image or video PHP?

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.

How can I tell what type of video a file is?

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.

How do I check if an image is valid in PHP?

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.


1 Answers

$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.

like image 54
Semas Avatar answered Sep 28 '22 06:09

Semas