From: Verdon V. <ve...@ve...> - 2005-07-26 15:18:42
|
Hi :) In a module of mine, I have a case where I need to check the mimetype of a file already on the server. In my initial attempt, I used... $type = mime_content_type($file); Then I discovered that mime_content_type may not be available in all php builds, and/or that it may not be enabled in php.ini. Some poking around the user comments on php.net showed me the following function, which seems to work well on my second server... if (!function_exists('mime_content_type')) { function mime_content_type($f) { $f = escapeshellarg($f); return trim( `file -bi $f` ); } } $type = mime_content_type($file); However, I suspect this will not work on a windows server. That leaves me with a couple options... 1) go with the above solution which I think will work for most people, and provide documentation for the rest 2) use function_exists('mime_content_type') and if it doesn't exist, don't even offer the module feature to the end user 3) use function_exists('mime_content_type') and if it doesn't exist, use a file ext check instead and map to mimetype (not very good I know) What I wonder if, is there is something in the phpws api that will do a similar job for me, that I am not aware of? Keep in mind, I'm dealing with a file already on the server, not one being uploaded. FYI... the module feature I am referring to above is one that I am calling an 'Import'. Basically, it allows the user to select a file already on the server (likely uploaded via ftp for instance) and register it with the module. By register it, I mean check the file for the correct/allowed mimetype, capture the mimetype, name, and size, and write it to the item's record in the db. I have provided this option as some users of the module could often be dealing with files larger than most servers max_upload_size. Thanks for any thoughts, verdon |