I want to allow users on my website to link to remote media objects: flash, music, movies, etc. I already have a regex to check for links:
/(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?/i
With the matched links, I want to check if they are media files instead of just checking for the the extension on the URL. I was thinking that I could just check the the HTTP headers for the content-type, but that might be a little too much—I was hoping that PHP might have some native functions already.
The FileInfo extension provides the
finfo_filefunction, which will give you the mimetype of a file.From its introduction manual page: