是否有可能以及如何确定给定的文件名或url字符串是否为视频的有效资源?我有一个项目,从rss源获取数据,只过滤视频。任何想法?
您需要的是curl_getinfo()
:
<?php
// get file headers
$ch = curl_init('http://www.test.com/data.avi');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
// get 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) {
// your code here
}
它允许您获得准确的MIME文件类型,并检查它是否是您需要的。
如果你只是想检查文件扩展名-你可以explode
url字符串点,获得最新的元素,并使用in_array
来检查它是否在允许的扩展名数组:
此处使用strpos
$url = 'http://example.com?index.php&file=mp4';
if (strpos($url,'mp4')) {
echo 'true';
}