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 in MIME Type. So, we can check the$_FILES['file']['mime_type']
and apply apreg_match()
to check if"audio/"
exists in this mime type or not.You can choose common audio extensions or all extensions into an array one time. Then validate through that array you have.
You must know all mime type's of audio and video, this is the list of audio & video mimes
and then check your file by using this
Here is the simple function