<?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: Validating File Extensions using&#160;PHP</title>
	<atom:link href="http://www.abeautifulsite.net/blog/2007/11/validating-file-extensions-using-php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.abeautifulsite.net/blog/2007/11/validating-file-extensions-using-php/</link>
	<description></description>
	<lastBuildDate>Thu, 02 Feb 2012 21:45:22 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>By: Nanny Ogg</title>
		<link>http://www.abeautifulsite.net/blog/2007/11/validating-file-extensions-using-php/#comment-579</link>
		<dc:creator>Nanny Ogg</dc:creator>
		<pubDate>Thu, 16 Jul 2009 00:15:55 +0000</pubDate>
		<guid isPermaLink="false">http://abs.lavitech.com/?p=44#comment-579</guid>
		<description>Hi Nima and Cory,
Thank you. Your combination of file extension validation code for PHP works beautifully.
Nanny</description>
		<content:encoded><![CDATA[<p>Hi Nima and Cory,<br />
Thank you. Your combination of file extension validation code for PHP works beautifully.<br />
Nanny</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nima</title>
		<link>http://www.abeautifulsite.net/blog/2007/11/validating-file-extensions-using-php/#comment-578</link>
		<dc:creator>Nima</dc:creator>
		<pubDate>Mon, 10 Dec 2007 19:36:23 +0000</pubDate>
		<guid isPermaLink="false">http://abs.lavitech.com/?p=44#comment-578</guid>
		<description>The dot problem.

i used pathinfo() instead and changed the code to this:

function check_extension($filename, $allowed, $case_sensitive = false) {
   $file_ext = pathinfo($filename);
   $ext = $file_ext[&#039;extension&#039;];
    if( !$case_sensitive ) {
        foreach( array_keys($allowed) as $key ) {
            $allowed[$key] = strtolower($allowed[$key]);
        }
        $file_ext = strtolower($file_ext);
    }
    if( in_array( $ext, $allowed ) ) return true; else return false;
}

now it works even if the filename contains more then one dot.</description>
		<content:encoded><![CDATA[<p>The dot problem.</p>
<p>i used pathinfo() instead and changed the code to this:</p>
<p>function check_extension($filename, $allowed, $case_sensitive = false) {<br />
   $file_ext = pathinfo($filename);<br />
   $ext = $file_ext['extension'];<br />
    if( !$case_sensitive ) {<br />
        foreach( array_keys($allowed) as $key ) {<br />
            $allowed[$key] = strtolower($allowed[$key]);<br />
        }<br />
        $file_ext = strtolower($file_ext);<br />
    }<br />
    if( in_array( $ext, $allowed ) ) return true; else return false;<br />
}</p>
<p>now it works even if the filename contains more then one dot.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cory LaViska</title>
		<link>http://www.abeautifulsite.net/blog/2007/11/validating-file-extensions-using-php/#comment-577</link>
		<dc:creator>Cory LaViska</dc:creator>
		<pubDate>Fri, 16 Nov 2007 22:09:11 +0000</pubDate>
		<guid isPermaLink="false">http://abs.lavitech.com/?p=44#comment-577</guid>
		<description>Thanks for the suggestions, Dan.  I&#039;ve updated the function using a regular expression to determine the file extension and in_array() instead of looping.  I also added an argument to make the comparison case-sensitive or not.  Otherwise, the function works exactly the way it used to.</description>
		<content:encoded><![CDATA[<p>Thanks for the suggestions, Dan.  I&#8217;ve updated the function using a regular expression to determine the file extension and in_array() instead of looping.  I also added an argument to make the comparison case-sensitive or not.  Otherwise, the function works exactly the way it used to.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan Dean</title>
		<link>http://www.abeautifulsite.net/blog/2007/11/validating-file-extensions-using-php/#comment-576</link>
		<dc:creator>Dan Dean</dc:creator>
		<pubDate>Thu, 15 Nov 2007 13:50:42 +0000</pubDate>
		<guid isPermaLink="false">http://abs.lavitech.com/?p=44#comment-576</guid>
		<description>There are a couple of ways you could make this function more efficient and fool-proof

1. instead of looping through the array to see if a given extension is in it, just is in_array() : http://us2.php.net/in_array

2. user regular expressions to find the last set of letters after the last period in the file name:
$str = &quot;radical.jpg&quot;;
$matches = null;
preg_match(&#039;/\w+$/&#039;,strtolower($str),$matches);
var_dump($matches[0]);</description>
		<content:encoded><![CDATA[<p>There are a couple of ways you could make this function more efficient and fool-proof</p>
<p>1. instead of looping through the array to see if a given extension is in it, just is in_array() : <a href="http://us2.php.net/in_array" rel="nofollow">http://us2.php.net/in_array</a></p>
<p>2. user regular expressions to find the last set of letters after the last period in the file name:<br />
$str = &#8220;radical.jpg&#8221;;<br />
$matches = null;<br />
preg_match(&#8216;/\w+$/&#8217;,strtolower($str),$matches);<br />
var_dump($matches[0]);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cory LaViska</title>
		<link>http://www.abeautifulsite.net/blog/2007/11/validating-file-extensions-using-php/#comment-575</link>
		<dc:creator>Cory LaViska</dc:creator>
		<pubDate>Tue, 13 Nov 2007 21:57:38 +0000</pubDate>
		<guid isPermaLink="false">http://abs.lavitech.com/?p=44#comment-575</guid>
		<description>Pablo: substr($filename, -3) will work, but only for 3 letter extensions.  A file&#039;s extension is always comprised of all the characters proceeding the last dot (.) in the filename :)</description>
		<content:encoded><![CDATA[<p>Pablo: substr($filename, -3) will work, but only for 3 letter extensions.  A file&#8217;s extension is always comprised of all the characters proceeding the last dot (.) in the filename :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pablo Impallari</title>
		<link>http://www.abeautifulsite.net/blog/2007/11/validating-file-extensions-using-php/#comment-574</link>
		<dc:creator>Pablo Impallari</dc:creator>
		<pubDate>Tue, 13 Nov 2007 21:28:28 +0000</pubDate>
		<guid isPermaLink="false">http://abs.lavitech.com/?p=44#comment-574</guid>
		<description>What if the filename have more dots:
like my.photo.gif

I allways do somethink like this:
substr($filename, -3)

Anyway.. good function, i will use it</description>
		<content:encoded><![CDATA[<p>What if the filename have more dots:<br />
like my.photo.gif</p>
<p>I allways do somethink like this:<br />
substr($filename, -3)</p>
<p>Anyway.. good function, i will use it</p>
]]></content:encoded>
	</item>
</channel>
</rss>

