如何在 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.
廣告