All right...kind of an involved problem, but here goes...
I'm attempting to create a small-scale asset management system. In this system, there are several ways for adding files, including <input file ...>, as well as grabbing a remote file.
Among other information, I'm storing these files' mime types in a mysql database. Initially, I was grabbing the mime types from uploaded files from the $FILES array ($FILES[...]['type']), but I realized this wasn't going to work from files added in other ways. So instead I created a general function, return_mime_type($file), that uses the UNIX command "file -ib $path" to return the mime type of a local file. I figured this was the best way - a standard method of returning mime types on all files.
However, there is a problem, and I suspect it's because I'm using a Mac (OS 9.2.2). When uploading/grabbing remote images, everything works fine. I get "image/gif" and "image/jpeg", etc... However, when uploading MP3 files, "file -ib" simply returns "data", which is the default to return when the command can't figure out what type of file it is fed. This happens when I use <input file ...> as well as when I use an FTP program (Transmit), and then add the file. However, when I grab an mp3 from a site I've worked on (where users are adding files using Windows FTP programs), "file -ib" returns "audio/mpeg." Additionally, when I grab the $_FILES[...]['type'] value from an uploaded MP3 file, it returns "audio/mpeg" (as it should.)
So basically, in a nutshell: uploading through IE 5.1 Mac (classic) and FTPing through Transmit creates a valid MP3 (plays fine over the web), but a UNIX command returns a generic mime type. Grabbing the mime type from the $_FILES variable returns a valid type. Using the same UNIX command on files uploaded through other FTP programs returns a valid type.
Anyone have any advice, either good or bad? 🙂 I wonder if I'm going to have strip out a resource fork, or something like that.