<?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: PHP Get File Extension</title>
	<atom:link href="http://cowburn.info/2008/01/13/get-file-extension-comparison/feed/" rel="self" type="application/rss+xml" />
	<link>http://cowburn.info/2008/01/13/get-file-extension-comparison/</link>
	<description>Online storage depot for Peter Cowburn</description>
	<lastBuildDate>Thu, 03 May 2012 06:33:06 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: Peter</title>
		<link>http://cowburn.info/2008/01/13/get-file-extension-comparison/#comment-73269</link>
		<dc:creator>Peter</dc:creator>
		<pubDate>Wed, 28 Mar 2012 20:05:59 +0000</pubDate>
		<guid isPermaLink="false">http://cowburn.info/php/get-file-extension-comparison/#comment-73269</guid>
		<description>Mr Doe, happy to be of service. Don&#039;t forget to clean up. ;)</description>
		<content:encoded><![CDATA[<p>Mr Doe, happy to be of service. Don&#8217;t forget to clean up. <img src='http://cowburn.info/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John doe</title>
		<link>http://cowburn.info/2008/01/13/get-file-extension-comparison/#comment-73268</link>
		<dc:creator>John doe</dc:creator>
		<pubDate>Wed, 28 Mar 2012 20:01:45 +0000</pubDate>
		<guid isPermaLink="false">http://cowburn.info/php/get-file-extension-comparison/#comment-73268</guid>
		<description>Wow a high level programming discussion, i came...</description>
		<content:encoded><![CDATA[<p>Wow a high level programming discussion, i came&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter</title>
		<link>http://cowburn.info/2008/01/13/get-file-extension-comparison/#comment-73005</link>
		<dc:creator>Peter</dc:creator>
		<pubDate>Mon, 19 Mar 2012 09:06:15 +0000</pubDate>
		<guid isPermaLink="false">http://cowburn.info/php/get-file-extension-comparison/#comment-73005</guid>
		<description>publo, &lt;code&gt;pathinfo()&lt;/code&gt; is &quot;secure&quot; in the sense that it does exactly, and only, the job requested of it as documented.  If you try to use &lt;code&gt;pathinfo()&lt;/code&gt; in a manner other than it is supposed to be used, then it is the developer&#039;s failing.  With regards to that article, the developer is simply demonstrating a completely incorrect method for &lt;em&gt;validating&lt;/em&gt; the input: &lt;code&gt;pathinfo()&lt;/code&gt; is still doing its job correctly.  The function is not insecure, the developer trying to use it where it is not appropriate, is.</description>
		<content:encoded><![CDATA[<p>publo, <code>pathinfo()</code> is &#8220;secure&#8221; in the sense that it does exactly, and only, the job requested of it as documented.  If you try to use <code>pathinfo()</code> in a manner other than it is supposed to be used, then it is the developer&#8217;s failing.  With regards to that article, the developer is simply demonstrating a completely incorrect method for <em>validating</em> the input: <code>pathinfo()</code> is still doing its job correctly.  The function is not insecure, the developer trying to use it where it is not appropriate, is.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: publo</title>
		<link>http://cowburn.info/2008/01/13/get-file-extension-comparison/#comment-73003</link>
		<dc:creator>publo</dc:creator>
		<pubDate>Mon, 19 Mar 2012 05:53:57 +0000</pubDate>
		<guid isPermaLink="false">http://cowburn.info/php/get-file-extension-comparison/#comment-73003</guid>
		<description>yo Peter

pathinfo() is not secure
http://www.madirish.net/?article=232</description>
		<content:encoded><![CDATA[<p>yo Peter</p>
<p>pathinfo() is not secure<br />
<a href="http://www.madirish.net/?article=232" rel="nofollow">http://www.madirish.net/?article=232</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eliud</title>
		<link>http://cowburn.info/2008/01/13/get-file-extension-comparison/#comment-72760</link>
		<dc:creator>Eliud</dc:creator>
		<pubDate>Sun, 11 Mar 2012 21:35:30 +0000</pubDate>
		<guid isPermaLink="false">http://cowburn.info/php/get-file-extension-comparison/#comment-72760</guid>
		<description>Hey, just here to drop a &quot;Thank You!&quot; for showing us this snippet of code. Very simple, but beats the way I was doing it by a mile (r by milliseconds, which is, a lot in terms of a script). Thank you!</description>
		<content:encoded><![CDATA[<p>Hey, just here to drop a &#8220;Thank You!&#8221; for showing us this snippet of code. Very simple, but beats the way I was doing it by a mile (r by milliseconds, which is, a lot in terms of a script). Thank you!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter</title>
		<link>http://cowburn.info/2008/01/13/get-file-extension-comparison/#comment-71958</link>
		<dc:creator>Peter</dc:creator>
		<pubDate>Fri, 17 Feb 2012 18:45:33 +0000</pubDate>
		<guid isPermaLink="false">http://cowburn.info/php/get-file-extension-comparison/#comment-71958</guid>
		<description>Dan, yes &lt;code&gt;pathinfo()&lt;/code&gt; will work with paths in &lt;code&gt;$_FILES&lt;/code&gt;. It just takes a string containing a &lt;em&gt;file path&lt;/em&gt; and doesn&#039;t care a jot where it came from.</description>
		<content:encoded><![CDATA[<p>Dan, yes <code>pathinfo()</code> will work with paths in <code>$_FILES</code>. It just takes a string containing a <em>file path</em> and doesn&#8217;t care a jot where it came from.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dan</title>
		<link>http://cowburn.info/2008/01/13/get-file-extension-comparison/#comment-71956</link>
		<dc:creator>dan</dc:creator>
		<pubDate>Fri, 17 Feb 2012 17:00:51 +0000</pubDate>
		<guid isPermaLink="false">http://cowburn.info/php/get-file-extension-comparison/#comment-71956</guid>
		<description>Hi,

does the pathinfo() method work with files in the $_FILES array in http post/get?

being unsure, i&#039;m using the explode way for now.

thanks for this post, it&#039;s cool.</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>does the pathinfo() method work with files in the $_FILES array in http post/get?</p>
<p>being unsure, i&#8217;m using the explode way for now.</p>
<p>thanks for this post, it&#8217;s cool.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter</title>
		<link>http://cowburn.info/2008/01/13/get-file-extension-comparison/#comment-71484</link>
		<dc:creator>Peter</dc:creator>
		<pubDate>Sat, 04 Feb 2012 12:58:26 +0000</pubDate>
		<guid isPermaLink="false">http://cowburn.info/php/get-file-extension-comparison/#comment-71484</guid>
		<description>Jacob, this is because &lt;code&gt;pathinfo()&lt;/code&gt; works on filesystem paths not URLs.  For your example with a URL, you could get the path by using &lt;a href=&quot;http://php.net/parse_url&quot; rel=&quot;nofollow&quot;&gt;&lt;code&gt;parse_url()&lt;/code&gt;&lt;/a&gt;.

&lt;pre lang=&quot;php&quot;&gt;
$path = parse_url($url, PHP_URL_PATH);
$ext  = pathinfo($path, PATHINFO_EXTENSION);
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Jacob, this is because <code>pathinfo()</code> works on filesystem paths not URLs.  For your example with a URL, you could get the path by using <a href="http://php.net/parse_url" rel="nofollow"><code>parse_url()</code></a>.</p>
<div class="codecolorer-container php twitlight moo-highlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$path</span> <span style="color: #339933;">=</span> <span style="color: #990000;">parse_url</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> PHP_URL_PATH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$ext</span> &nbsp;<span style="color: #339933;">=</span> <span style="color: #990000;">pathinfo</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #339933;">,</span> PATHINFO_EXTENSION<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jakob Sternberg</title>
		<link>http://cowburn.info/2008/01/13/get-file-extension-comparison/#comment-71446</link>
		<dc:creator>Jakob Sternberg</dc:creator>
		<pubDate>Sat, 04 Feb 2012 02:57:52 +0000</pubDate>
		<guid isPermaLink="false">http://cowburn.info/php/get-file-extension-comparison/#comment-71446</guid>
		<description>The only thing that fails is if the path has a query line attached. Like 

&lt;pre lang=&quot;php&quot;&gt;echo pathinfo(&quot;http://mysite.com/page.php?file=msg.txt&quot;, PATHINFO_EXTENSION)&lt;/pre&gt;
- it will output &#039;txt&#039;

Just a note. easy to fix offcourse:

&lt;pre lang=&quot;php&quot;&gt;function getFileExtension($p) {
   if( strpos($p,&quot;?&quot;) != &#039;&#039; ) $p = substr($p, 0, strpos($p,&quot;?&quot;) ); 
   return pathinfo($p, PATHINFO_EXTENSION);
   }

echo getFileExtension(&quot;http://mysite.com/page.php?file=msg.txt&quot;)
&lt;/pre&gt;

- will output &#039;php&#039;

Thanks for the heads up on PATHINFO_EXTENSION!</description>
		<content:encoded><![CDATA[<p>The only thing that fails is if the path has a query line attached. Like</p>
<div class="codecolorer-container php twitlight moo-highlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">echo</span> <span style="color: #990000;">pathinfo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://mysite.com/page.php?file=msg.txt&quot;</span><span style="color: #339933;">,</span> PATHINFO_EXTENSION<span style="color: #009900;">&#41;</span></div></div>
<p>- it will output &#8216;txt&#8217;</p>
<p>Just a note. easy to fix offcourse:</p>
<div class="codecolorer-container php twitlight moo-highlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">function</span> getFileExtension<span style="color: #009900;">&#40;</span><span style="color: #000088;">$p</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$p</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;?&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span> <span style="color: #009900;">&#41;</span> <span style="color: #000088;">$p</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$p</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$p</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;?&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp;<span style="color: #b1b100;">return</span> <span style="color: #990000;">pathinfo</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$p</span><span style="color: #339933;">,</span> PATHINFO_EXTENSION<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #b1b100;">echo</span> getFileExtension<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://mysite.com/page.php?file=msg.txt&quot;</span><span style="color: #009900;">&#41;</span></div></div>
<p>- will output &#8216;php&#8217;</p>
<p>Thanks for the heads up on PATHINFO_EXTENSION!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ram Kishor Agrawal</title>
		<link>http://cowburn.info/2008/01/13/get-file-extension-comparison/#comment-71304</link>
		<dc:creator>Ram Kishor Agrawal</dc:creator>
		<pubDate>Wed, 01 Feb 2012 06:52:58 +0000</pubDate>
		<guid isPermaLink="false">http://cowburn.info/php/get-file-extension-comparison/#comment-71304</guid>
		<description>Beautifully explained. Thanks!</description>
		<content:encoded><![CDATA[<p>Beautifully explained. Thanks!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

