<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ivan Villareal</title>
	<atom:link href="http://blog.ivanvillareal.info/tag/fileinfo/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.ivanvillareal.info</link>
	<description>IT stuff and more...</description>
	<lastBuildDate>Fri, 13 Aug 2010 23:05:31 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>File Type Detection in PHP</title>
		<link>http://blog.ivanvillareal.info/linux/file-type-detecion-in-php/</link>
		<comments>http://blog.ivanvillareal.info/linux/file-type-detecion-in-php/#comments</comments>
		<pubDate>Fri, 25 Dec 2009 04:47:24 +0000</pubDate>
		<dc:creator>Ivan Villareal</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[fileinfo]]></category>
		<category><![CDATA[pecl]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://blog.ivanvillareal.info/?p=150</guid>
		<description><![CDATA[I&#8217;m working on a project where the users can upload files, and I need to know the type of file they are uploading, a simple solution would be to check the extensions of the files, but this has many flaws, so I was looking for a reliable way to detect the type of file, and [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working on a project where the users can upload files, and I need to know the type of file they are uploading, a simple solution would be to check the extensions of the files, but this has many flaws, so I was looking for a reliable way to detect the type of file, and I found a PECL extension called <a href="http://pecl.php.net/package/Fileinfo/php-src/ext/fileinfo">file info</a> this extension is enabled by default in PHP 5.3, unfortunately I&#8217;m runing PHP 5.2.10, and the prod server also has this version.</p>
<p>So what I did to install this on ubuntu 9.10 karmic was the following:</p>
<p>&nbsp;</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Bash"><div class="devcodeoverflow">root<span style="color: #000000; font-weight: bold;">@</span>mini:<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>php5<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #666666; font-style: italic;"># apt-get install php5-dev libmagic-dev php-pear</span>
....
root<span style="color: #000000; font-weight: bold;">@</span>mini:<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>php5<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #666666; font-style: italic;"># pear channel-update pear.php.net</span>
...
root<span style="color: #000000; font-weight: bold;">@</span>mini:<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>php5<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #666666; font-style: italic;"># pecl install Fileinfo</span>
....
Build process completed successfully
Installing <span style="color: #ff0000;">'/usr/lib/php5/20060613+lfs/fileinfo.so'</span>
<span style="color: #c20cb9; font-weight: bold;">install</span> ok: channel:<span style="color: #000000; font-weight: bold;">//</span>pear.php.net<span style="color: #000000; font-weight: bold;">/</span>Fileinfo-1.0.4</div></pre><!--END_DEVFMTCODE--></p>
<p>&nbsp;</p>
<p>and finally I added the extension to php.ini</p>
<p>extension=fileinfo.so</p>
<p>I restarted the apache server, and tested with this</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="PHP"><div class="devcodeoverflow">          <span style="color: #339933;">&lt;!--</span>DVFMTSC<span style="color: #339933;">--&gt;</span><span style="color: #000088;">$fileInfo</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> finfo<span style="color: #009900;">&#40;</span>FILEINFO_MIME<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #339933;">&lt;!--</span>DVFMTSC<span style="color: #339933;">--&gt;</span> 
<span style="color: #000088;">$mimeType</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$fileInfo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">buffer</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$uploadedFile</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
</div></pre><!--END_DEVFMTCODE--></p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ivanvillareal.info/linux/file-type-detecion-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- www.000webhost.com Analytics Code -->
<script type="text/javascript" src="http://analytics.hosting24.com/count.php"></script>
<noscript><a href="http://www.hosting24.com/"><img src="http://analytics.hosting24.com/count.php" alt="web hosting" /></a></noscript>
<!-- End Of Analytics Code -->
