检查文件是否是PHP中的音频文件 [英] check if the file is audio file in PHP

查看:119
本文介绍了检查文件是否是PHP中的音频文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写上传音频文件的代码(可以是任何格式的.mp3,mp4,.wav等等)
我不想为所有的mime类型编写所有的条件,然后检查上传的文件来验证MIME类型。因为,我想接受所有的音频文件(不只是一种或两种格式)。

那么,有没有简单的方法来检查文件是否是音频文件

谢谢!

解决方案

所有的音频文件格式audio / common。因此,我们可以检查 $ _ FILES ['file'] ['mime_type'] 并应用 preg_match()检查这个MIME类型是否存在audio /


I'm writing code to upload audio file (could be in any format .mp3, mp4, .wav and many more...) I dont want to write all the conditions for all the mime types and then check uploaded file to validate the mime type. Because, I want to ACCEPT ALL the audio files(not just one or two formats).

So, is there any simple way to check whether the file is audio or not?

Thank you!

解决方案

All the audio files format has "audio/" common. So, we can check the $_FILES['file']['mime_type'] and apply a preg_match() to check if "audio/" exists in this mime type or not.

这篇关于检查文件是否是PHP中的音频文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆