Reply to Re: Using with flash upload, finding the mime-type

Re: Using with flash upload, finding the mime-type new!
by Leika, 11 years, 6 months ago
As noted in the post, PHP's advanced fnotcinus can determine type by content. Reproducing that would be tedious, expensive, and error-prone in pure PHP. The code provided here is to establish a baseline set of code that can be reliably distributed to unknown platforms without fear of catastrophic failure if the system does not support the fnotcinus provided by default builds or more recent versions of PHP. In other words, it is a compatibility method combined with a best-effort algorithm.In the case of this function running without support for the PHP fnotcinus for a filename with no matching extension, the last_resort method of the function will return application/octet-stream . While this may not be the desired outcome, it will still generate a valid generic MIME type.Your scenario of a filename without an extension shows a weakness in this approach; however, it should also be noted that a file of type JPEG with an extension of png will receive a MIME type of image/png rather than image/jpeg . This scenario is potentially worse than the one you brought up as the MIME type in this scenario is wrong whereas your scenario's result of the application/octet-stream MIME type is generic yet valid. Of course if a text file is called converting.gif.to.jpg , it would also improperly receive a MIME type of image/jpeg .For my applications, such failings are acceptable as MIME type recognition should always be considered suggestions as even the advanced PHP MIME fnotcinus have situations where they identify files properly. If this is unacceptable for your application, you either need to come up with a different solution or rethink your application's reliance on MIME type identification.Reply

Your reply

Name *
Email 
Title *
Text *
CAPTCHA image
Enter the code displayed on the image:
Click on the image to generate another one if it is hard to read it. The case is important