<?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"
	>

<channel>
	<title>Kalkran.COM</title>
	<atom:link href="http://kalkran.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://kalkran.com</link>
	<description>Design&#38;Coding</description>
	<pubDate>Wed, 30 Jul 2008 22:20:53 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
	<language>en</language>
			<item>
		<title>Recursion</title>
		<link>http://kalkran.com/misc/recursion/</link>
		<comments>http://kalkran.com/misc/recursion/#comments</comments>
		<pubDate>Wed, 30 Jul 2008 22:18:58 +0000</pubDate>
		<dc:creator>Kalkran</dc:creator>
		
		<category><![CDATA[Miscellaneous]]></category>

		<guid isPermaLink="false">http://kalkran.com/?p=135</guid>
		<description><![CDATA[No, I'm not dead yet =)
I've still been working on the WP Theme Generator,  which nobody is using. I found that my webhost has the php setting for adding slashes turned on by default. My code relied on having no slashes. To fix this, I had to write a short recursive function, which I'll [...]]]></description>
			<content:encoded><![CDATA[<p>No, I'm not dead yet =)</p>
<p>I've still been working on the WP Theme Generator,  which nobody is using. I found that my webhost has the php setting for adding slashes turned on by default. My code relied on having no slashes. To fix this, I had to write a short recursive function, which I'll share here, and then explain.</p>
<p>Recursion, it's just a fancy word for a function, in which it calls to itself. Like function a() { a(); }. That would provide an infinite loop, but it's the most simple recursive function.</p>
<p>So, my situation, the $_GET and $_POST vars had slashes added. And I wanted to strip them out, but I would like my function to accept both strings and arrays, for sake of convenience and consistency (always use my function, instead of sometimes stripslashes()). What I wrote was this:</p>
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> ss_<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$in</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/is_array"><span style="color: #000066;">is_array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$in</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">// It's an array, loop through all the keys and strip them.</span>
		<span style="color: #b1b100;">foreach</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$in</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$key</span> =&gt; <span style="color: #0000ff;">$value</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
			<span style="color: #0000ff;">$in</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$key</span><span style="color: #66cc66;">&#93;</span> = ss_<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$value</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// &lt;= Reference to itself, recursion!</span>
		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$in</span>;
	<span style="color: #66cc66;">&#125;</span><span style="color: #b1b100;">elseif</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/is_string"><span style="color: #000066;">is_string</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$in</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">// Regular stripslashes</span>
		<span style="color: #b1b100;">return</span> <a href="http://www.php.net/stripslashes"><span style="color: #000066;">stripslashes</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$in</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #66cc66;">&#123;</span> <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">null</span>; <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre>
<p>Comments say it all, really.<br />
Just another quick example would be a countdown function:</p>
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> countdown<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$num</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$num</span>, <span style="color: #ff0000;">'&lt;br/&gt;'</span>;
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$num</span> == <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span>; <span style="color: #808080; font-style: italic;">// Stop countin at 0.</span>
	countdown<span style="color: #66cc66;">&#40;</span>--<span style="color: #0000ff;">$num</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// --$num subtracts the one from $num before the value is read. $num-- does it after.</span>
	<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$num</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
countdown<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>That all for now, folks.</p>
<br/><a href="http://www.socialmarker.com/?link=http://kalkran.com/misc/recursion/&title=Recursion&text=No%2C+I%27m+not+dead+yet+%3D%29+I%27ve+still+been+working+on+the+WP+Theme+Generator%2C++which+nobody+is+using.+I+found+that+my+webhost+has+the+php+setting+for+adding+slashes+turned+on+by+default.&tags=function%2C+return" target="_blank"><img src= "http://www.socialmarker.com/bookmark.gif" border="0" /></a><noscript><a href="http://www.socialmarker.com" >Social Bookmarking</a></noscript><br />]]></content:encoded>
			<wfw:commentRss>http://kalkran.com/misc/recursion/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Cronjobs</title>
		<link>http://kalkran.com/misc/cronjobs/</link>
		<comments>http://kalkran.com/misc/cronjobs/#comments</comments>
		<pubDate>Mon, 21 Jul 2008 00:54:32 +0000</pubDate>
		<dc:creator>Kalkran</dc:creator>
		
		<category><![CDATA[Miscellaneous]]></category>

		<guid isPermaLink="false">http://kalkran.com/?p=131</guid>
		<description><![CDATA[
I've just set up my very first cronjob, to take out the trash of the theme generator. So  here's a warning, if you're creating a theme there sunday morning around 3.00 am, or wednesday morning around 3.00 am, you have a chance your files are going to be deleted midway through your process..
BAWWWWWWWWW...
Tutorial on Cronjobs [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_132" class="wp-caption alignnone" style="width: 509px"><a href="http://kalkran.com/wp-content/uploads/2008/07/cron.jpg"><img class="size-full wp-image-132" title="Cronjob Interface" src="http://kalkran.com/wp-content/uploads/2008/07/cron.jpg" alt="The Cronjob Interface" width="499" height="141" /></a><p class="wp-caption-text">The Cronjob Interface</p></div>
<p>I've just set up my very first cronjob, to take out the trash of the theme generator. So  here's a warning, if you're creating a theme there sunday morning around 3.00 am, or wednesday morning around 3.00 am, you have a chance your files are going to be deleted midway through your process..<br />
BAWWWWWWWWW...</p>
<p>Tutorial on Cronjobs will follow :-)</p>
<br/><a href="http://www.socialmarker.com/?link=http://kalkran.com/misc/cronjobs/&title=Cronjobs&text=%5Bcaption+id%3D%22attachment_132%22+align%3D%22alignnone%22+width%3D%22499%22+caption%3D%22The+Cronjob+Interface%22%5D%5B%2Fcaption%5D+I%27ve+just+set+up+my+very+first+cronjob%2C+to+take+out+the+trash+of+the+theme+generator.&tags=" target="_blank"><img src= "http://www.socialmarker.com/bookmark.gif" border="0" /></a><noscript><a href="http://www.socialmarker.com" >Social Bookmarking</a></noscript><br />]]></content:encoded>
			<wfw:commentRss>http://kalkran.com/misc/cronjobs/feed/</wfw:commentRss>
		</item>
		<item>
		<title>WordPress Theme Generator</title>
		<link>http://kalkran.com/misc/wordpress-theme-generator/</link>
		<comments>http://kalkran.com/misc/wordpress-theme-generator/#comments</comments>
		<pubDate>Sun, 20 Jul 2008 19:02:39 +0000</pubDate>
		<dc:creator>Kalkran</dc:creator>
		
		<category><![CDATA[Miscellaneous]]></category>

		<category><![CDATA[Web development]]></category>

		<category><![CDATA[creator]]></category>

		<category><![CDATA[generator]]></category>

		<category><![CDATA[theme]]></category>

		<category><![CDATA[themes]]></category>

		<category><![CDATA[wordpress]]></category>

		<category><![CDATA[wp]]></category>

		<guid isPermaLink="false">http://kalkran.com/?p=129</guid>
		<description><![CDATA[You'll never guess what I've made now! :).
A theme generator, which takes in regular templates (all HTML), and turns them into a 'basic' template, with a widget-ready sidebar, archive support, comments, and what not!
Click
Please let me know what you think in the comments section. And, please; Do note that this is a beta version, hmm [...]]]></description>
			<content:encoded><![CDATA[<p>You'll never guess what I've made now! :).</p>
<p>A theme generator, which takes in regular templates (all HTML), and turns them into a 'basic' template, with a widget-ready sidebar, archive support, comments, and what not!</p>
<p><a title="Theme Creator" href="http://kalkran.com/theme-creator/">Click</a></p>
<p>Please let me know what you think in the comments section. And, please; Do note that this is a beta version, hmm let's make up a number. Let's call it version Oh-point-six ?</p>
<p>Thanks for reading.</p>
<br/><a href="http://www.socialmarker.com/?link=http://kalkran.com/misc/wordpress-theme-generator/&title=WordPress+Theme+Generator&text=You%27ll+never+guess+what+I%27ve+made+now%21+%3A%29.+A+theme+generator%2C+which+takes+in+regular+templates+%28all+HTML%29%2C+and+turns+them+into+a+%27basic%27+template%2C+with+a+widget-ready+sidebar%2C+archive+support%2C...&tags=" target="_blank"><img src= "http://www.socialmarker.com/bookmark.gif" border="0" /></a><noscript><a href="http://www.socialmarker.com" >Social Bookmarking</a></noscript><br />]]></content:encoded>
			<wfw:commentRss>http://kalkran.com/misc/wordpress-theme-generator/feed/</wfw:commentRss>
		</item>
		<item>
		<title>CSS Hyperlink Tooltips</title>
		<link>http://kalkran.com/tutorials/web-development/css-hyperlink-tooltips/</link>
		<comments>http://kalkran.com/tutorials/web-development/css-hyperlink-tooltips/#comments</comments>
		<pubDate>Sat, 19 Jul 2008 13:05:03 +0000</pubDate>
		<dc:creator>Kalkran</dc:creator>
		
		<category><![CDATA[Web development]]></category>

		<guid isPermaLink="false">http://kalkran.com/?p=123</guid>
		<description><![CDATA[Ever wanted nicely styled CSS tooltips?
Here's a quick explanation:
&#160;
&#60;a href=&#34;#&#34;&#62;Link text&#60;span&#62;Your tooltip&#60;/span&#62;&#60;/a&#62;
Use that HTML. Then add the following to your stylesheet:
&#160;
a &#123; position: relative; outline: none; &#125;
a span &#123; display: none; &#125;
a:hover span &#123;
display: block;
font-size: 8pt;
position: absolute;
top:-25px; left: -45px;
border:1px solid #383a47;
background-color:#5cbbe3;
color: #383a47;
text-align: center;
padding: 1px 5px;
width: 130px; &#125;
This code hides the span tag when you're not [...]]]></description>
			<content:encoded><![CDATA[<p>Ever wanted nicely styled CSS tooltips?</p>
<p>Here's a quick explanation:</p>
<pre>&nbsp;
&lt;a href=&quot;#&quot;&gt;Link text&lt;span&gt;Your tooltip&lt;/span&gt;&lt;/a&gt;</pre>
<p>Use that HTML. Then add the following to your stylesheet:</p>
<pre class="css">&nbsp;
a <span style="color: #66cc66;">&#123;</span> <span style="color: #000000; font-weight: bold;">position</span>: <span style="color: #993333;">relative</span>; <span style="color: #000000; font-weight: bold;">outline</span>: <span style="color: #993333;">none</span>; <span style="color: #66cc66;">&#125;</span>
a span <span style="color: #66cc66;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span>: <span style="color: #993333;">none</span>; <span style="color: #66cc66;">&#125;</span>
a<span style="color: #3333ff;">:hover</span> span <span style="color: #66cc66;">&#123;</span>
<span style="color: #000000; font-weight: bold;">display</span>: <span style="color: #993333;">block</span>;
<span style="color: #000000; font-weight: bold;">font-size</span>: <span style="color: #933;">8pt</span>;
<span style="color: #000000; font-weight: bold;">position</span>: <span style="color: #993333;">absolute</span>;
top<span style="color: #3333ff;">:-<span style="color: #933;">25px</span></span>; <span style="color: #000000; font-weight: bold;">left</span>: -<span style="color: #933;">45px</span>;
border<span style="color: #3333ff;">:<span style="color: #933;">1px</span></span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#383a47</span>;
<span style="color: #000000; font-weight: bold;">background-color</span>:<span style="color: #cc00cc;">#5cbbe3</span>;
<span style="color: #000000; font-weight: bold;">color</span>: <span style="color: #cc00cc;">#383a47</span>;
<span style="color: #000000; font-weight: bold;">text-align</span>: <span style="color: #993333;">center</span>;
<span style="color: #000000; font-weight: bold;">padding</span>: <span style="color: #933;">1px</span> <span style="color: #933;">5px</span>;
<span style="color: #000000; font-weight: bold;">width</span>: <span style="color: #933;">130px</span>; <span style="color: #66cc66;">&#125;</span></pre>
<p>This code hides the span tag when you're not hovering over it. (a span { display: none; }) and positions it nicely when you DO hover over it.<br />
Read on for an example (just a single hyperlink, but it's not valid xhtml so I put it on a different page)<br />
<span id="more-123"></span></p>
<style type="text/css">a.example { position: relative; outline: none; } 
a.example span { display: none; }
a.example:hover span { display: block; font-size: 8pt; position: absolute; top:-25px; left: 0px; border:1px solid #000; background-color:#5cbbe3; color: #383a47; text-align: center; padding: 1px 5px; width: 130px; font-weight: none; text-decoration: none; font-weight:  normal; }</style>
<p><a href="#" class="example">Hover over me!<span>Wow, a tooltip!</span></a></p>
<br/><a href="http://www.socialmarker.com/?link=http://kalkran.com/tutorials/web-development/css-hyperlink-tooltips/&title=CSS+Hyperlink+Tooltips&text=Ever+wanted+nicely+styled+CSS+tooltips%3F+Here%27s+a+quick+explanation%3A+%26nbsp%3B+%26lt%3Ba+href%3D%26quot%3B%23%26quot%3B%26gt%3BLink+text%26lt%3Bspan%26gt%3BYour+tooltip%26lt%3B%2Fspan%26gt%3B%26lt%3B%2Fa%26gt%3B+Use+that+HTML.&tags=display+none%3B%2C+none%3B%2C+display" target="_blank"><img src= "http://www.socialmarker.com/bookmark.gif" border="0" /></a><noscript><a href="http://www.socialmarker.com" >Social Bookmarking</a></noscript><br />]]></content:encoded>
			<wfw:commentRss>http://kalkran.com/tutorials/web-development/css-hyperlink-tooltips/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Designing a website layout</title>
		<link>http://kalkran.com/misc/designing-a-website-layout/</link>
		<comments>http://kalkran.com/misc/designing-a-website-layout/#comments</comments>
		<pubDate>Fri, 18 Jul 2008 19:45:22 +0000</pubDate>
		<dc:creator>Kalkran</dc:creator>
		
		<category><![CDATA[Miscellaneous]]></category>

		<guid isPermaLink="false">http://kalkran.com/?p=116</guid>
		<description><![CDATA[
I'm personally not the creative type, being original with design is very hard for me. I just can't think of that special thing to do to make a design unique. So the thing I did was: sit down, pull out a sketchbook and a pen. And just draw a regular layout. Then switch some things [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_117" class="wp-caption alignright" style="width: 160px"><a href="http://kalkran.com/wp-content/uploads/2008/07/img014.jpg"><img class="size-thumbnail wp-image-117" title="Web Design Steps" src="http://kalkran.com/wp-content/uploads/2008/07/img014-150x150.jpg" alt="The steps I took for designing my new layout" width="150" height="150" /></a><p class="wp-caption-text">The steps I took for designing my new layout</p></div>
<p>I'm personally not the creative type, being original with design is very hard for me. I just can't think of that special thing to do to make a design unique. So the thing I did was: sit down, pull out a sketchbook and a pen. And just draw a regular layout. Then switch some things around, and you have a general layout to work with. This is what I came up with:</p>
<p>That's what my next layout (which will be a wordpress theme) will look like, at least, that's what I'm aiming for.</p>
<p>So I'll be focusing on that, using photoshop. I'll be sure to keep you updated.</p>
<p>One more thing: <a title="Cypher" href="http://cypher.extremecast.com/?ref=Kalkran">Cypher</a>. An online text-based hacking game. By clicking that link and signing up, you're selecting me as the referrer so you'll be making me 100 credits! Woot!</p>
<p><a href="http://cypher.extremecast.com/?ref=Kalkran"><img src="http://cypher.extremecast.com/stats/Kalkran.png" border="0"></a></p>
<br/><a href="http://www.socialmarker.com/?link=http://kalkran.com/misc/designing-a-website-layout/&title=Designing+a+website+layout&text=%5Bcaption+id%3D%22attachment_117%22+align%3D%22alignright%22+width%3D%22150%22+caption%3D%22The+steps+I+took+for+designing+my+new+layout%22%5D%5B%2Fcaption%5D+I%27m+personally+not+the+creative+type%2C+being+original+with+design+is+very...&tags=" target="_blank"><img src= "http://www.socialmarker.com/bookmark.gif" border="0" /></a><noscript><a href="http://www.socialmarker.com" >Social Bookmarking</a></noscript><br />]]></content:encoded>
			<wfw:commentRss>http://kalkran.com/misc/designing-a-website-layout/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Wordpress 2.6</title>
		<link>http://kalkran.com/misc/wordpress-26/</link>
		<comments>http://kalkran.com/misc/wordpress-26/#comments</comments>
		<pubDate>Thu, 17 Jul 2008 15:25:12 +0000</pubDate>
		<dc:creator>Kalkran</dc:creator>
		
		<category><![CDATA[Miscellaneous]]></category>

		<guid isPermaLink="false">http://kalkran.com/?p=108</guid>
		<description><![CDATA[So,
Like the rest of all the Wordpress users, I've upgraded to 2.6. I was one of the first too, updated about ~10 minutes after the release! Here's a little demo, from the wordpress website:
 
I find that the Theme Viewer does its work great :). And it's nice to have the plugins sorted instead of [...]]]></description>
			<content:encoded><![CDATA[<p>So,</p>
<p>Like the rest of all the Wordpress users, I've upgraded to 2.6. I was one of the first too, updated about ~10 minutes after the release! Here's a little demo, from the wordpress website:</p>
<p><embed src="http://v.wordpress.com/mARhRBcT/fmt_std" type="application/x-shockwave-flash" width="400" height="250" flashvars="blog_domain=http://wordpress.org/development/2008/07/wordpress-26/&width=400&height=250"> </embed></p>
<p>I find that the Theme Viewer does its work great :). And it's nice to have the plugins sorted instead of having activated and not activated randomly in between.</p>
<p><a href="http://wordpress.org/latest.zip">Get Wordpress 2.6</a></p>
<br/><a href="http://www.socialmarker.com/?link=http://kalkran.com/misc/wordpress-26/&title=Wordpress+2.6&text=So%2C+Like+the+rest+of+all+the+Wordpress+users%2C+I%27ve+upgraded+to+2.6.+I+was+one+of+the+first+too%2C+updated+about+%7E10+minutes+after+the+release%21&tags=" target="_blank"><img src= "http://www.socialmarker.com/bookmark.gif" border="0" /></a><noscript><a href="http://www.socialmarker.com" >Social Bookmarking</a></noscript><br />]]></content:encoded>
			<wfw:commentRss>http://kalkran.com/misc/wordpress-26/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Using clear in CSS</title>
		<link>http://kalkran.com/tutorials/web-development/using-clear-in-css/</link>
		<comments>http://kalkran.com/tutorials/web-development/using-clear-in-css/#comments</comments>
		<pubDate>Mon, 14 Jul 2008 22:36:20 +0000</pubDate>
		<dc:creator>Kalkran</dc:creator>
		
		<category><![CDATA[Web development]]></category>

		<category><![CDATA[css]]></category>

		<guid isPermaLink="false">http://kalkran.com/?p=107</guid>
		<description><![CDATA[If you ever use floats, and then tried to add content to a container that's not floated, you may have experienced the same issues that many have. The solution is far simpler than expected
&#160;
.clear &#123; clear: both; &#125;
This forces any item with a class of clear to be clear of floats on the left and [...]]]></description>
			<content:encoded><![CDATA[<p>If you ever use floats, and then tried to add content to a container that's not floated, you may have experienced the same issues that many have. The solution is far simpler than expected</p>
<pre class="css">&nbsp;
<span style="color: #6666ff;">.clear</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #000000; font-weight: bold;">clear</span>: <span style="color: #993333;">both</span>; <span style="color: #66cc66;">&#125;</span></pre>
<p>This forces any item with a class of <em>clear</em> to be clear of floats on the left and right, which are - by chance - the other two options to <em>clear</em>; left and right. So after floating elements left and right, you should add a <span class="clear"></span> to force content below.</p>
<br/><a href="http://www.socialmarker.com/?link=http://kalkran.com/tutorials/web-development/using-clear-in-css/&title=Using+clear+in+CSS&text=If+you+ever+use+floats%2C+and+then+tried+to+add+content+to+a+container+that%27s+not+floated%2C+you+may+have+experienced+the+same+issues+that+many+have.+The+solution+is+far+simpler+than+expected+%26nbsp%3B...&tags=and+right" target="_blank"><img src= "http://www.socialmarker.com/bookmark.gif" border="0" /></a><noscript><a href="http://www.socialmarker.com" >Social Bookmarking</a></noscript><br />]]></content:encoded>
			<wfw:commentRss>http://kalkran.com/tutorials/web-development/using-clear-in-css/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Faking an AJAX upload script</title>
		<link>http://kalkran.com/tutorials/faking-an-ajax-upload-script/</link>
		<comments>http://kalkran.com/tutorials/faking-an-ajax-upload-script/#comments</comments>
		<pubDate>Mon, 14 Jul 2008 14:53:09 +0000</pubDate>
		<dc:creator>Kalkran</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://kalkran.com/?p=104</guid>
		<description><![CDATA[Ever wanted to make an upload script, but don't want the page to refresh? Try AJAX.
In this tutorial we'll use an iframe to simulate AJAX behaviour.
Firstly, we "might" want to create a simple upload form:
&#160;
&#60;p id=&#34;f1_upload_process&#34;&#62;Loading...&#60;br/&#62;&#60;img src=&#34;loader.gif&#34; /&#62;
&#60;p id=&#34;result&#34;&#62;
&#60;form action=&#34;admin/addpost.php&#34; method=&#34;post&#34; enctype=&#34;multipart/form-data&#34; target=&#34;upload_target&#34; onsubmit=&#34;startUpload();&#34; &#62;
		File:
&#60;input name=&#34;myfile&#34; type=&#34;file&#34; /&#62;
&#60;input type=&#34;submit&#34; name=&#34;submitBtn&#34; value=&#34;Upload&#34; /&#62;
	&#60;/form&#62;
&#160;
	&#60;iframe id=&#34;upload_target&#34; name=&#34;upload_target&#34; src=&#34;#&#34; [...]]]></description>
			<content:encoded><![CDATA[<p>Ever wanted to make an upload script, but don't want the page to refresh? Try AJAX.</p>
<p>In this tutorial we'll use an iframe to simulate AJAX behaviour.</p>
<p>Firstly, we "might" want to create a simple upload form:</p>
<pre>&nbsp;
&lt;p id=&quot;f1_upload_process&quot;&gt;Loading...&lt;br/&gt;&lt;img src=&quot;loader.gif&quot; /&gt;
&lt;p id=&quot;result&quot;&gt;
&lt;form action=&quot;admin/addpost.php&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot; target=&quot;upload_target&quot; onsubmit=&quot;startUpload();&quot; &gt;
		File:
&lt;input name=&quot;myfile&quot; type=&quot;file&quot; /&gt;
&lt;input type=&quot;submit&quot; name=&quot;submitBtn&quot; value=&quot;Upload&quot; /&gt;
	&lt;/form&gt;
&nbsp;
	&lt;iframe id=&quot;upload_target&quot; name=&quot;upload_target&quot; src=&quot;#&quot; style=&quot;width:0;height:0;border:0px solid #fff;&quot;&gt;&lt;/iframe&gt;
&nbsp;</pre>
<p>The important part here is the enctype, always have the enctype specified if you're uploading files. The first paragraph is the little Loading... box that'll show up when we press the submit button. The second &lt;p&gt; "result" is to display the results (We've uploaded or We failed). And lastly the iframe that is actually submitting the data, specified through the target="upload_target" in the form. Also, the forms onsubmit triggers the startUpload(); function.</p>
<p>Now we want to add some Javascript functions:<br />
<span id="more-104"></span></p>
<pre class="javascript">&nbsp;
&nbsp;
&lt;script type=<span style="color: #3366CC;">&quot;text/javascript&quot;</span>&gt;
<span style="color: #003366; font-weight: bold;">function</span> startUpload<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
document.<span style="color: #006600;">getElementById</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'f1_upload_process'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">style</span>.<span style="color: #006600;">visibility</span> = <span style="color: #3366CC;">'visible'</span>;
<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #003366; font-weight: bold;">function</span> stopUpload<span style="color: #66cc66;">&#40;</span>success<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>success == <span style="color: #CC0000;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
document.<span style="color: #006600;">getElementById</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'result'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">innerHTML</span> =
<span style="color: #3366CC;">'
&lt;div class=&quot;msg&quot;&gt;The file was uploaded successfully!&lt;/div&gt;
&nbsp;
'</span>;
<span style="color: #66cc66;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #66cc66;">&#123;</span>
document.<span style="color: #006600;">getElementById</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'result'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">innerHTML</span> =
<span style="color: #3366CC;">'
&lt;div id=&quot;error&quot;&gt;There was an error during file upload!&lt;/div&gt;
&nbsp;
'</span>;
<span style="color: #66cc66;">&#125;</span>
document.<span style="color: #006600;">getElementById</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'f1_upload_process'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">style</span>.<span style="color: #006600;">visibility</span> = <span style="color: #3366CC;">'hidden'</span>;
<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span>;
<span style="color: #66cc66;">&#125;</span>
&lt;/script&gt;</pre>
<p>The function called startUpload(); does nothing more than show the #f1_upload_process div which contains the text "Loading..." and an image. the stopUpload function, though, checks the success variable passed to it, and adjusts the text of the #result accordingly and hides the "Loading".</p>
<p>So far, we have an ugly form. Lets add some style to it, make it look good.</p>
<pre class="css">&nbsp;
&nbsp;
<span style="color: #cc00cc;">#f1_upload_process</span><span style="color: #66cc66;">&#123;</span>
z-index<span style="color: #3333ff;">:<span style="color: #933;">100</span></span>;
position<span style="color: #3333ff;">:absolute</span>;
visibility<span style="color: #3333ff;">:hidden</span>;
text-align<span style="color: #3333ff;">:center</span>;
width<span style="color: #3333ff;">:<span style="color: #933;">400px</span></span>;
margin<span style="color: #3333ff;">:<span style="color: #933;">0px</span></span>;
padding<span style="color: #3333ff;">:<span style="color: #933;">0px</span></span>;
<span style="color: #000000; font-weight: bold;">background-color</span>:<span style="color: #cc00cc;">#fff</span>;
border<span style="color: #3333ff;">:<span style="color: #933;">1px</span></span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#ccc</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
form<span style="color: #66cc66;">&#91;</span>target=<span style="color: #ff0000;">'upload_target'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#123;</span>
text-align<span style="color: #3333ff;">:center</span>;
width<span style="color: #3333ff;">:<span style="color: #933;">390px</span></span>;
margin<span style="color: #3333ff;">:<span style="color: #933;">0px</span></span>;
padding<span style="color: #3333ff;">:<span style="color: #933;">5px</span></span>;
<span style="color: #000000; font-weight: bold;">background-color</span>:<span style="color: #cc00cc;">#fff</span>;
border<span style="color: #3333ff;">:<span style="color: #933;">1px</span></span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#ccc</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p>I've used a conditional parameter on the form, so all other forms can stay as they are, and I didn't have to give the form an id or class. Then, one more thing; the PHP:</p>
<pre class="php">&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #000066;">isset</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$_FILES</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'myfile'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> :
<span style="color: #0000ff;">$destination_path</span> = <span style="color: #ff0000;">&quot;./&quot;</span>; <span style="color: #808080; font-style: italic;">// This folder (don't forget trailing /)</span>
<span style="color: #0000ff;">$result</span> = <span style="color: #cc66cc;">0</span>; <span style="color: #808080; font-style: italic;">// Not succesful yet</span>
<span style="color: #0000ff;">$target_path</span> = <span style="color: #0000ff;">$destination_path</span> . <a href="http://www.php.net/basename"><span style="color: #000066;">basename</span></a><span style="color: #66cc66;">&#40;</span> <span style="color: #0000ff;">$_FILES</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'myfile'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'name'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// Target path (This folder + Filename);</span>
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>@<a href="http://www.php.net/move_uploaded_file"><span style="color: #000066;">move_uploaded_file</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$_FILES</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'myfile'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'tmp_name'</span><span style="color: #66cc66;">&#93;</span>, <span style="color: #0000ff;">$target_path</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #808080; font-style: italic;">// move the file</span>
<span style="color: #0000ff;">$result</span> = <span style="color: #cc66cc;">1</span>; <span style="color: #808080; font-style: italic;">// success!</span>
<span style="color: #66cc66;">&#125;</span>
<a href="http://www.php.net/sleep"><span style="color: #000066;">sleep</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">// Echo the javascript to call the stopUpload function.</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;script language</span>=<span style="color: #ff0000;">&quot;javascript&quot;</span> type=<span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;
window.top.window.stopUpload<span style="color: #66cc66;">&#40;</span>&amp;lt;?php <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$result</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<a href="http://www.php.net/die"><span style="color: #000066;">die</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// Dont forget this, if not you'll echo the form again.</span>
<span style="color: #b1b100;">endif</span>;
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;</pre>
<p>Now save it as a PHP file and run it on your webserver, voila.</p>
<p><a href="http://kalkran.com/wp-content/uploads/2008/07/fakeajax.phps">Click to download source</a></p>
<br/><a href="http://www.socialmarker.com/?link=http://kalkran.com/tutorials/faking-an-ajax-upload-script/&title=Faking+an+AJAX+upload+script&text=Ever+wanted+to+make+an+upload+script%2C+but+don%27t+want+the+page+to+refresh%3F+Try+AJAX.+In+this+tutorial+we%27ll+use+an+iframe+to+simulate+AJAX+behaviour.&tags=%26nbsp%3B%2C+%26%23125%3B%2C+function%2C+result%2C+javascript%2C+upload_target%2C+script" target="_blank"><img src= "http://www.socialmarker.com/bookmark.gif" border="0" /></a><noscript><a href="http://www.socialmarker.com" >Social Bookmarking</a></noscript><br />]]></content:encoded>
			<wfw:commentRss>http://kalkran.com/tutorials/faking-an-ajax-upload-script/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
