<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.0.2" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: PHP, Mime Types and Fileinfo</title>
	<link>http://www.jellyandcustard.com/2006/01/19/php-mime-types-and-fileinfo/</link>
	<description>Web Development Blog</description>
	<pubDate>Sat, 05 Jul 2008 00:13:58 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.2</generator>

	<item>
		<title>by: How To Force File Download With PHP &#124; W-Shadow.com</title>
		<link>http://www.jellyandcustard.com/2006/01/19/php-mime-types-and-fileinfo/#comment-15306</link>
		<pubDate>Sun, 12 Aug 2007 15:16:46 +0000</pubDate>
		<guid>http://www.jellyandcustard.com/2006/01/19/php-mime-types-and-fileinfo/#comment-15306</guid>
					<description>[...] Related info Determining MIME type of a file automatically More on determining the MIME type Common MIME types HTTP, caching and other stuff   Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages. [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] Related info Determining MIME type of a file automatically More on determining the MIME type Common MIME types HTTP, caching and other stuff   Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages. [&#8230;]
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Malversán</title>
		<link>http://www.jellyandcustard.com/2006/01/19/php-mime-types-and-fileinfo/#comment-2308</link>
		<pubDate>Fri, 16 Feb 2007 12:47:00 +0000</pubDate>
		<guid>http://www.jellyandcustard.com/2006/01/19/php-mime-types-and-fileinfo/#comment-2308</guid>
					<description>&lt;blockquote&gt;$mime_type = $fi-&amp;#62;buffer(file_get_contents($file));&lt;/blockquote&gt;

It's a total waste of memory to load file contents into a variable if you're dealing with big files.

There's an easier solution with the finfo class, although you won't find it in the (always outdated) PHP documentation.

&lt;blockquote&gt;$mime_type = $fi-&amp;#62;file($file);&lt;/blockquote&gt;

In fact it was you who helped me to figure that there was a '-&amp;#62;file()' method. I was searching for an example of FileInfo usage and the only one I found was this page.

Regards.</description>
		<content:encoded><![CDATA[<blockquote><p>$mime_type = $fi-&gt;buffer(file_get_contents($file));</p></blockquote>
<p>It&#039;s a total waste of memory to load file contents into a variable if you&#039;re dealing with big files.</p>
<p>There&#039;s an easier solution with the finfo class, although you won&#039;t find it in the (always outdated) PHP documentation.</p>
<blockquote><p>$mime_type = $fi-&gt;file($file);</p></blockquote>
<p>In fact it was you who helped me to figure that there was a &#039;-&gt;file()&#039; method. I was searching for an example of FileInfo usage and the only one I found was this page.</p>
<p>Regards.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: bart bosma</title>
		<link>http://www.jellyandcustard.com/2006/01/19/php-mime-types-and-fileinfo/#comment-1748</link>
		<pubDate>Tue, 23 Jan 2007 13:03:42 +0000</pubDate>
		<guid>http://www.jellyandcustard.com/2006/01/19/php-mime-types-and-fileinfo/#comment-1748</guid>
					<description>I think Jason's shell solution doesn't works in windows, and it's way too much code just to get a 'stupid' mime type :).

i think the mime_content_type followed by the fileinfo fc. are the best choices..</description>
		<content:encoded><![CDATA[<p>I think Jason&#039;s shell solution doesn&#039;t works in windows, and it&#039;s way too much code just to get a &#039;stupid&#039; mime type <img src='http://www.jellyandcustard.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p>i think the mime_content_type followed by the fileinfo fc. are the best choices..
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Jason</title>
		<link>http://www.jellyandcustard.com/2006/01/19/php-mime-types-and-fileinfo/#comment-1033</link>
		<pubDate>Wed, 01 Nov 2006 23:17:22 +0000</pubDate>
		<guid>http://www.jellyandcustard.com/2006/01/19/php-mime-types-and-fileinfo/#comment-1033</guid>
					<description>If you have shell_exec ability, you can also use the following method.  I've found it to be as accurate and just as simple.
&lt;code&gt;
//format file path in case it contains strange chars or spaces
$fileCommandPath = escapeshellarg('/abs/path/to/file.ext');

//get response from shell &quot;file&quot; command.  note use of backtick operator
$fileCommandResult = trim(`file -bi $fileCommandPath`);		

//sometimes &quot;file -bi&quot; returns extra data with mime type. only use string before &quot;;&quot;
$fileCommandResult = explode(';', $fileCommandResult);
		
//pretty sure the real mime type of the file is...
$mime_type = $fileCommandResult[0];
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>If you have shell_exec ability, you can also use the following method.  I&#039;ve found it to be as accurate and just as simple.<br />
<code><br />
//format file path in case it contains strange chars or spaces<br />
$fileCommandPath = escapeshellarg('/abs/path/to/file.ext');</p>
<p>//get response from shell "file" command.  note use of backtick operator<br />
$fileCommandResult = trim(`file -bi $fileCommandPath`);		</p>
<p>//sometimes "file -bi" returns extra data with mime type. only use string before ";"<br />
$fileCommandResult = explode(';', $fileCommandResult);</p>
<p>//pretty sure the real mime type of the file is...<br />
$mime_type = $fileCommandResult[0];<br />
</code>
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Using DirectoryIterator to List Files in PHP &#183; Jelly &#38; Custard</title>
		<link>http://www.jellyandcustard.com/2006/01/19/php-mime-types-and-fileinfo/#comment-231</link>
		<pubDate>Thu, 18 May 2006 17:07:18 +0000</pubDate>
		<guid>http://www.jellyandcustard.com/2006/01/19/php-mime-types-and-fileinfo/#comment-231</guid>
					<description>[...] getType() - get file type (not MIME Type) [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] getType() - get file type (not MIME Type) [&#8230;]
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Sergio Álvarez (xergio)</title>
		<link>http://www.jellyandcustard.com/2006/01/19/php-mime-types-and-fileinfo/#comment-25</link>
		<pubDate>Mon, 06 Feb 2006 02:06:40 +0000</pubDate>
		<guid>http://www.jellyandcustard.com/2006/01/19/php-mime-types-and-fileinfo/#comment-25</guid>
					<description>&lt;strong&gt;Gentoo, PHP5 y mime_content_type()&lt;/strong&gt;

Esto es para recordarlo cuando en un futuro me vuelva a pasar.Quer&amp;#237;a usar la funci&amp;#243;n mime_content_type() en PHP5, la cual me da el MIME Type de un archivo (vamos, el tipo de archivo que es seg&amp;#250;n el contenido). Pero resulta que en G...</description>
		<content:encoded><![CDATA[<p><strong>Gentoo, PHP5 y mime_content_type()</strong>Esto es para recordarlo cuando en un futuro me vuelva a pasar.Quer&iacute;a usar la funci&oacute;n mime_content_type() en PHP5, la cual me da el MIME Type de un archivo (vamos, el tipo de archivo que es seg&uacute;n el contenido). Pero resulta que en G&#8230;
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Ben</title>
		<link>http://www.jellyandcustard.com/2006/01/19/php-mime-types-and-fileinfo/#comment-21</link>
		<pubDate>Thu, 19 Jan 2006 15:06:14 +0000</pubDate>
		<guid>http://www.jellyandcustard.com/2006/01/19/php-mime-types-and-fileinfo/#comment-21</guid>
					<description>Very useful post!

You can also use &lt;a href=&quot;http://uk2.php.net/mime-content-type&quot; rel=&quot;nofollow&quot;&gt;mime_content_type()&lt;/a&gt; for determining Mime types.

Its absolutely imperative that your scripts check the mime type of uploaded files, since the $_FILES array's contents is determined by the browser NOT the server. If the user is on MSIE the mime-type is simply picked out by the file extension not the file's headers, leaving a nice big hole for exploitation.</description>
		<content:encoded><![CDATA[<p>Very useful post!</p>
<p>You can also use <a href="http://uk2.php.net/mime-content-type" rel="nofollow">mime_content_type()</a> for determining Mime types.</p>
<p>Its absolutely imperative that your scripts check the mime type of uploaded files, since the $_FILES array&#039;s contents is determined by the browser NOT the server. If the user is on MSIE the mime-type is simply picked out by the file extension not the file&#039;s headers, leaving a nice big hole for exploitation.
</p>
]]></content:encoded>
				</item>
</channel>
</rss>
