<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Generating MIME Type in PHP is not Magic</title>
	<atom:link href="http://chrisjean.com/2009/02/14/generating-mime-type-in-php-is-not-magic/feed/" rel="self" type="application/rss+xml" />
	<link>http://chrisjean.com/2009/02/14/generating-mime-type-in-php-is-not-magic/</link>
	<description>Linux, WordPress, programming, anime, and other stuff</description>
	<lastBuildDate>Fri, 18 May 2012 19:58:32 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: PHP MIME</title>
		<link>http://chrisjean.com/2009/02/14/generating-mime-type-in-php-is-not-magic/comment-page-1/#comment-19343</link>
		<dc:creator>PHP MIME</dc:creator>
		<pubDate>Fri, 16 Mar 2012 08:20:00 +0000</pubDate>
		<guid isPermaLink="false">http://gaarai.com/?p=1031#comment-19343</guid>
		<description>Thank you a lot for writing this helpful article. 
Have a nice day.</description>
		<content:encoded><![CDATA[<p>Thank you a lot for writing this helpful article.<br />
Have a nice day.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Jean</title>
		<link>http://chrisjean.com/2009/02/14/generating-mime-type-in-php-is-not-magic/comment-page-1/#comment-18118</link>
		<dc:creator>Chris Jean</dc:creator>
		<pubDate>Tue, 10 Jan 2012 19:37:19 +0000</pubDate>
		<guid isPermaLink="false">http://gaarai.com/?p=1031#comment-18118</guid>
		<description>Does your comment have anything to do with what I&#039;m talking about in this post, or are you simply looking for someone to help you fix your code?

If you read this post, I talk about why the finfo_open() may not be available on all systems.</description>
		<content:encoded><![CDATA[<p>Does your comment have anything to do with what I&#8217;m talking about in this post, or are you simply looking for someone to help you fix your code?</p>
<p>If you read this post, I talk about why the finfo_open() may not be available on all systems.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sunday igoche</title>
		<link>http://chrisjean.com/2009/02/14/generating-mime-type-in-php-is-not-magic/comment-page-1/#comment-18117</link>
		<dc:creator>sunday igoche</dc:creator>
		<pubDate>Tue, 10 Jan 2012 19:30:46 +0000</pubDate>
		<guid isPermaLink="false">http://gaarai.com/?p=1031#comment-18117</guid>
		<description>Fatal error: Call to undefined function finfo_open() in C:\wamp\www\testing\test.php on line 47

the code in line 47 is:  $finfo = finfo_open(FILEINFO_MIME_TYPE); 

please help.</description>
		<content:encoded><![CDATA[<p>Fatal error: Call to undefined function finfo_open() in C:\wamp\www\testing\test.php on line 47</p>
<p>the code in line 47 is:  $finfo = finfo_open(FILEINFO_MIME_TYPE); </p>
<p>please help.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michele</title>
		<link>http://chrisjean.com/2009/02/14/generating-mime-type-in-php-is-not-magic/comment-page-1/#comment-17435</link>
		<dc:creator>Michele</dc:creator>
		<pubDate>Sat, 10 Dec 2011 21:26:45 +0000</pubDate>
		<guid isPermaLink="false">http://gaarai.com/?p=1031#comment-17435</guid>
		<description>You have made my day. Thank you :P</description>
		<content:encoded><![CDATA[<p>You have made my day. Thank you <img src='http://chrisjean.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Get MIME type of file using PHP &#124; Aqua Smit</title>
		<link>http://chrisjean.com/2009/02/14/generating-mime-type-in-php-is-not-magic/comment-page-1/#comment-15388</link>
		<dc:creator>Get MIME type of file using PHP &#124; Aqua Smit</dc:creator>
		<pubDate>Fri, 07 Oct 2011 09:11:29 +0000</pubDate>
		<guid isPermaLink="false">http://gaarai.com/?p=1031#comment-15388</guid>
		<description>[...] http://chrisjean.com/2009/02/14/generating-mime-type-in-php-is-not-magic/   This entry was posted in Uncategorized by admin. Bookmark the permalink. [...]</description>
		<content:encoded><![CDATA[<p>[...] <a href="http://chrisjean.com/2009/02/14/generating-mime-type-in-php-is-not-magic/" rel="nofollow">http://chrisjean.com/2009/02/14/generating-mime-type-in-php-is-not-magic/</a>   This entry was posted in Uncategorized by admin. Bookmark the permalink. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gaarai</title>
		<link>http://chrisjean.com/2009/02/14/generating-mime-type-in-php-is-not-magic/comment-page-1/#comment-2084</link>
		<dc:creator>gaarai</dc:creator>
		<pubDate>Mon, 30 Aug 2010 21:01:10 +0000</pubDate>
		<guid isPermaLink="false">http://gaarai.com/?p=1031#comment-2084</guid>
		<description>Relying on the &quot;file&quot; program is a severe code portability issue. Failure would easily occur if the system does not have the file program, the file program uses a different parameter syntax, or the platform does not support the program (Windows).</description>
		<content:encoded><![CDATA[<p>Relying on the &#8220;file&#8221; program is a severe code portability issue. Failure would easily occur if the system does not have the file program, the file program uses a different parameter syntax, or the platform does not support the program (Windows).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: devsforev</title>
		<link>http://chrisjean.com/2009/02/14/generating-mime-type-in-php-is-not-magic/comment-page-1/#comment-2078</link>
		<dc:creator>devsforev</dc:creator>
		<pubDate>Thu, 26 Aug 2010 16:05:04 +0000</pubDate>
		<guid isPermaLink="false">http://gaarai.com/?p=1031#comment-2078</guid>
		<description>Thank you for this nice workaround! I too was struggling yesterday with determining the mime-type. It&#039;s for a script that sends email attachments. My GoDaddy host runs PHP 5.2.8, so FileInfo was not available, and mime_content_type did not exist either. Another trick I&#039;ve used in the past:

exec(file -bi $file);

Didn&#039;t work either :-/. Apparently the &quot;file&quot; program is not installed on my host... Your workaround solved my problems. Thanks!</description>
		<content:encoded><![CDATA[<p>Thank you for this nice workaround! I too was struggling yesterday with determining the mime-type. It&#8217;s for a script that sends email attachments. My GoDaddy host runs PHP 5.2.8, so FileInfo was not available, and mime_content_type did not exist either. Another trick I&#8217;ve used in the past:</p>
<p>exec(file -bi $file);</p>
<p>Didn&#8217;t work either :-/. Apparently the &#8220;file&#8221; program is not installed on my host&#8230; Your workaround solved my problems. Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gaarai</title>
		<link>http://chrisjean.com/2009/02/14/generating-mime-type-in-php-is-not-magic/comment-page-1/#comment-2051</link>
		<dc:creator>gaarai</dc:creator>
		<pubDate>Thu, 19 Aug 2010 13:55:35 +0000</pubDate>
		<guid isPermaLink="false">http://gaarai.com/?p=1031#comment-2051</guid>
		<description>As noted in the post, PHP&#039;s advanced functions 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 functions 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 functions for a filename with no matching extension, the last_resort method of the function will return &quot;application/octet-stream&quot;. 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 &quot;image/png&quot; rather than &quot;image/jpeg&quot;. This scenario is potentially worse than the one you brought up as the MIME type in this scenario is wrong whereas your scenario&#039;s result of the &quot;application/octet-stream&quot; MIME type is generic yet valid. Of course if a text file is called &quot;converting.gif.to.jpg&quot;, it would also improperly receive a MIME type of &quot;image/jpeg&quot;.

For my applications, such failings are acceptable as MIME type recognition should always be considered suggestions as even the advanced PHP MIME functions 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&#039;s reliance on MIME type identification.</description>
		<content:encoded><![CDATA[<p>As noted in the post, PHP&#8217;s advanced functions 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 functions provided by default builds or more recent versions of PHP. In other words, it is a compatibility method combined with a best-effort algorithm.</p>
<p>In the case of this function running without support for the PHP functions for a filename with no matching extension, the last_resort method of the function will return &#8220;application/octet-stream&#8221;. While this may not be the desired outcome, it will still generate a valid generic MIME type.</p>
<p>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 &#8220;image/png&#8221; rather than &#8220;image/jpeg&#8221;. This scenario is potentially worse than the one you brought up as the MIME type in this scenario is wrong whereas your scenario&#8217;s result of the &#8220;application/octet-stream&#8221; MIME type is generic yet valid. Of course if a text file is called &#8220;converting.gif.to.jpg&#8221;, it would also improperly receive a MIME type of &#8220;image/jpeg&#8221;.</p>
<p>For my applications, such failings are acceptable as MIME type recognition should always be considered suggestions as even the advanced PHP MIME functions 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&#8217;s reliance on MIME type identification.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eddie</title>
		<link>http://chrisjean.com/2009/02/14/generating-mime-type-in-php-is-not-magic/comment-page-1/#comment-2050</link>
		<dc:creator>Eddie</dc:creator>
		<pubDate>Thu, 19 Aug 2010 13:34:37 +0000</pubDate>
		<guid isPermaLink="false">http://gaarai.com/?p=1031#comment-2050</guid>
		<description>Your code fails to detect MIME types at all when the file does not have an extension and neither finfo_openn or mime_content_type are available.

How do you propose that?</description>
		<content:encoded><![CDATA[<p>Your code fails to detect MIME types at all when the file does not have an extension and neither finfo_openn or mime_content_type are available.</p>
<p>How do you propose that?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: acatalept</title>
		<link>http://chrisjean.com/2009/02/14/generating-mime-type-in-php-is-not-magic/comment-page-1/#comment-1926</link>
		<dc:creator>acatalept</dc:creator>
		<pubDate>Tue, 04 May 2010 15:59:48 +0000</pubDate>
		<guid isPermaLink="false">http://gaarai.com/?p=1031#comment-1926</guid>
		<description>Outstanding... I&#039;ve been hitting a brick wall getting mime types working after upgrading to PHP 5.3 (still says &quot;undefined function finfo_open()&quot; strangely enough).

Very elegant, portable solution.  Thanks!</description>
		<content:encoded><![CDATA[<p>Outstanding&#8230; I&#8217;ve been hitting a brick wall getting mime types working after upgrading to PHP 5.3 (still says &#8220;undefined function finfo_open()&#8221; strangely enough).</p>
<p>Very elegant, portable solution.  Thanks!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

