I am allowing users to upload files to my server, so I need to detect if a file is an audio file. I attempted to check based on the MIME type using mime_content_type($path)
but often times it returns application/octet-stream
. If it were an image I could use getimagesize()
so is there an equivalent for audio files?
2
Answers
what if you open the file directly to get the mime type
Mp3 data detection is a wierd thing. There is a serious tradeof to be made between reading/processing alot of data or just looking for certain values at specified locations.
As far as mime-type detection goes i think [correct me if i am wrong]
application/octet-stream
is the default fallback type.if you want a quick and dirty but performant solution i sugest just using the file extension
*.mp3
to determine it’s type.If the reliabilty of this functionality is crucial [higher priority than performance]
you can use a library like ffprobe [from ffmpeg].