<?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"
	>
<channel>
	<title>Comments on: Giving an Uploaded File a Unique Name in PHP</title>
	<atom:link href="http://www.indywebshop.com/bestpractices/2008/01/10/giving-an-uploaded-file-a-unique-name-in-php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.indywebshop.com/bestpractices/2008/01/10/giving-an-uploaded-file-a-unique-name-in-php/</link>
	<description>presented by Site Potion</description>
	<pubDate>Wed, 20 Aug 2008 15:37:02 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: Clay</title>
		<link>http://www.indywebshop.com/bestpractices/2008/01/10/giving-an-uploaded-file-a-unique-name-in-php/#comment-36755</link>
		<dc:creator>Clay</dc:creator>
		<pubDate>Wed, 23 Jan 2008 01:02:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.indywebshop.com/bestpractices/2008/01/10/giving-an-uploaded-file-a-unique-name-in-php/#comment-36755</guid>
		<description>@Noah: Good upgrade!</description>
		<content:encoded><![CDATA[<p>@Noah: Good upgrade!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Noah</title>
		<link>http://www.indywebshop.com/bestpractices/2008/01/10/giving-an-uploaded-file-a-unique-name-in-php/#comment-36754</link>
		<dc:creator>Noah</dc:creator>
		<pubDate>Thu, 10 Jan 2008 19:09:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.indywebshop.com/bestpractices/2008/01/10/giving-an-uploaded-file-a-unique-name-in-php/#comment-36754</guid>
		<description>You know you're a nerd when this kind of thing is actually fun.

I'm not always the best at optimizing code, but I do love the challenge of trying to figure out how to make code do what you want. So, here's my shot at it.

Replace this line:
$fulldest = str_replace(”.”,”$i.”,$originaldest);

With these two lines:
$ext = strrchr($originaldest, ".");
$fulldest = str_replace($ext,$i.$ext,$originaldest);

You could do it in one line, but then you'd have to run the strrchr function twice. The first line looks for the last period in the string and returns the period everything after it (which I assume is always the file extension).

The second line uses the first line's result to search and replace just the file extension and slap the integer variable in front of it. Thus avoiding the "my1.precious1.file1.jpg" problem.

Here is my reference: http://us.php.net/manual/en/function.strrchr.php (I've learned so much from php.net)

Thanks for making me think! :) Your snippet will likely come in handy.</description>
		<content:encoded><![CDATA[<p>You know you&#8217;re a nerd when this kind of thing is actually fun.</p>
<p>I&#8217;m not always the best at optimizing code, but I do love the challenge of trying to figure out how to make code do what you want. So, here&#8217;s my shot at it.</p>
<p>Replace this line:<br />
$fulldest = str_replace(”.”,”$i.”,$originaldest);</p>
<p>With these two lines:<br />
$ext = strrchr($originaldest, &#8220;.&#8221;);<br />
$fulldest = str_replace($ext,$i.$ext,$originaldest);</p>
<p>You could do it in one line, but then you&#8217;d have to run the strrchr function twice. The first line looks for the last period in the string and returns the period everything after it (which I assume is always the file extension).</p>
<p>The second line uses the first line&#8217;s result to search and replace just the file extension and slap the integer variable in front of it. Thus avoiding the &#8220;my1.precious1.file1.jpg&#8221; problem.</p>
<p>Here is my reference: <a href="http://us.php.net/manual/en/function.strrchr.php" rel="nofollow">http://us.php.net/manual/en/function.strrchr.php</a> (I&#8217;ve learned so much from php.net)</p>
<p>Thanks for making me think! <img src='http://www.indywebshop.com/bestpractices/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> Your snippet will likely come in handy.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
