如何在 php 中检查文件是否为视频类型?
假设您的变量如下,其中我们有一个 .mp4 路径文件 -
$movieFileType="demo.mp4";
为了检查上述文件是否为视频类型,请使用 end() 以及 explode(). 您需要将其设置到 strtolower() 中并检查条件 -
if(strtolower(end(explode(".",$movieFileType))) =="mp4") {
}
else {
}示例
<!DOCTYPE html>
<html>
<body>
<?php
$movieFileType="demo.mp4";
if(strtolower(end(explode(".",$movieFileType))) =="mp4") {
echo "The movie ",$movieFileType," is of video type.";
} else {
echo "The movie ",$movieFileType," is not of video type.";
}
?>
</body>
</html>这将生成以下输出 -
输出
The movie demo.mp4 is of video type.
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP