PHP Script to identify if given file name string or url string is of valid video mimetype -
is possible , how determine if given string of filename or url valid resource video? have project fetches data rss feed , filter videos. idea? in advance.
what need curl_getinfo()
:
<?php // file headers $ch = curl_init('http://www.test.com/data.avi'); curl_setopt($ch, curlopt_returntransfer, true); curl_exec($ch); // content type $allowed_content_types = array("video/x-msvideo", "video/mp4"); $content_type = curl_getinfo($ch, curlinfo_content_type); if (in_array($content_type, $allowed_content_types) { // code here }
it allows accurate mime type of file , check if it's 1 need.
if want check file extensions - can explode
url string dot, latest element , use in_array
check if in array of allowed extensions:
$url = "http://test.com/data.avi"; $extension = pathinfo("test.s.d", pathinfo_extension); $allowed_extensions = array("avi", "mp4"); if (in_array($extension, $allowed_extensions) { // code here }
Comments
Post a Comment