<?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>MaggsWeb:7 &#187; function</title>
	<atom:link href="http://www.maggsweb.com/tag/function/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.maggsweb.com</link>
	<description>www.maggsweb.com</description>
	<lastBuildDate>Sat, 21 Aug 2010 20:50:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Compressing CSS files &#8211; on the fly</title>
		<link>http://www.maggsweb.com/php/compressing-files-on-the-fly/</link>
		<comments>http://www.maggsweb.com/php/compressing-files-on-the-fly/#comments</comments>
		<pubDate>Tue, 20 Jul 2010 07:30:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[compress]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[function]]></category>

		<guid isPermaLink="false">http://www.maggsweb.com/?p=978</guid>
		<description><![CDATA[I hate compressing CSS files as they become totally unreadable for editing. I end up keeping 2 versions, compressed and uncompressed, etc.. But how about compressing all your CSS files into one file, &#8216;on-the-fly&#8217;. Now that has solved the problem. ?View Code PHP&#60;?php &#160; header&#40;'Content-type: text/css'&#41;; &#160; ob_start&#40;&#34;compress&#34;&#41;; &#160; function compress&#40;$buffer&#41; &#123; /* remove comments [...]]]></description>
			<content:encoded><![CDATA[<p>I hate compressing CSS files as they become totally unreadable for editing.  I end up keeping 2 versions, compressed and uncompressed, etc..   But how about compressing all your CSS files into one file, &#8216;on-the-fly&#8217;.  Now that has solved the problem.</p>
<p><span id="more-978"></span></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?" onclick="pageTracker._trackPageview('/outgoing/www.ericbess.com/ericblog/2008/03/03/wp-codebox/_examples?referer=');"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p978code3'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p9783"><td class="code" id="p978code3"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<a href="http://www.php.net/header" onclick="pageTracker._trackPageview('/outgoing/www.php.net/header?referer=');"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-type: text/css'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<a href="http://www.php.net/ob_start" onclick="pageTracker._trackPageview('/outgoing/www.php.net/ob_start?referer=');"><span style="color: #990000;">ob_start</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;compress&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> compress<span style="color: #009900;">&#40;</span><span style="color: #000088;">$buffer</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">/* remove comments */</span>
  <span style="color: #000088;">$buffer</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/preg_replace" onclick="pageTracker._trackPageview('/outgoing/www.php.net/preg_replace?referer=');"><span style="color: #990000;">preg_replace</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'!/\*[^*]*\*+([^/][^*]*\*+)*/!'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$buffer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">/* remove tabs, spaces, newlines, etc. */</span>
  <span style="color: #000088;">$buffer</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/str_replace" onclick="pageTracker._trackPageview('/outgoing/www.php.net/str_replace?referer=');"><span style="color: #990000;">str_replace</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array" onclick="pageTracker._trackPageview('/outgoing/www.php.net/array?referer=');"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'  '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'    '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'    '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$buffer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$buffer</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* your css files */</span>
<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'master.css'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'typography.css'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'grid.css'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'print.css'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'handheld.css'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<a href="http://www.php.net/ob_end_flush" onclick="pageTracker._trackPageview('/outgoing/www.php.net/ob_end_flush?referer=');"><span style="color: #990000;">ob_end_flush</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Use it like this :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?" onclick="pageTracker._trackPageview('/outgoing/www.ericbess.com/ericblog/2008/03/03/wp-codebox/_examples?referer=');"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p978code4'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p9784"><td class="code" id="p978code4"><pre class="html" style="font-family:monospace;">&lt;link rel=&quot;stylesheet&quot; href=&quot;style.php&quot; type=&quot;text/css&quot; media=&quot;all&quot;&gt;</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.maggsweb.com/php/compressing-files-on-the-fly/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>First date of the week</title>
		<link>http://www.maggsweb.com/php/first-date-of-the-week/</link>
		<comments>http://www.maggsweb.com/php/first-date-of-the-week/#comments</comments>
		<pubDate>Thu, 08 Jul 2010 10:06:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[function]]></category>

		<guid isPermaLink="false">http://www.maggsweb.com/?p=965</guid>
		<description><![CDATA[Just a little script I wrote to work out the date of the first day of the week. ?View Code PHP&#60;?php &#160; $yearNow = date&#40;'Y', $time&#41;; $monthNow = date&#40;'m', $time&#41;; $dayNow = date&#40;'d', $time&#41;; &#160; $first_day_of_week = 'Mon'; // Sat &#124; Sun &#124; Mon &#124; etc.. $day = $dayNow; // dont overwrite $dayNow! &#160; while [...]]]></description>
			<content:encoded><![CDATA[<p>Just a little script I wrote to work out the date of the first day of the week.<br />
<span id="more-965"></span></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?" onclick="pageTracker._trackPageview('/outgoing/www.ericbess.com/ericblog/2008/03/03/wp-codebox/_examples?referer=');"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p965code6'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p9656"><td class="code" id="p965code6"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000088;">$yearNow</span>  <span style="color: #339933;">=</span> <a href="http://www.php.net/date" onclick="pageTracker._trackPageview('/outgoing/www.php.net/date?referer=');"><span style="color: #990000;">date</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Y'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$time</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$monthNow</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/date" onclick="pageTracker._trackPageview('/outgoing/www.php.net/date?referer=');"><span style="color: #990000;">date</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'m'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$time</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dayNow</span>   <span style="color: #339933;">=</span> <a href="http://www.php.net/date" onclick="pageTracker._trackPageview('/outgoing/www.php.net/date?referer=');"><span style="color: #990000;">date</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'d'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$time</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$first_day_of_week</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Mon'</span><span style="color: #339933;">;</span>   <span style="color: #666666; font-style: italic;">// Sat | Sun | Mon | etc..  </span>
<span style="color: #000088;">$day</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$dayNow</span><span style="color: #339933;">;</span>               <span style="color: #666666; font-style: italic;">// dont overwrite $dayNow!</span>
&nbsp;
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$weekday</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$first_day_of_week</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$weekday</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/date" onclick="pageTracker._trackPageview('/outgoing/www.php.net/date?referer=');"><span style="color: #990000;">date</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'D'</span><span style="color: #339933;">,</span><a href="http://www.php.net/mktime" onclick="pageTracker._trackPageview('/outgoing/www.php.net/mktime?referer=');"><span style="color: #990000;">mktime</span></a><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #000088;">$monthNow</span><span style="color: #339933;">,</span><span style="color: #000088;">$day</span><span style="color: #339933;">,</span><span style="color: #000088;">$yearNow</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$weekday</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$first_day_of_week</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
         <span style="color: #000088;">$first_date_of_week</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$day</span><span style="color: #339933;">;</span>
         <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span> 
     <span style="color: #000088;">$day</span><span style="color: #339933;">--;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;h2&gt;First date of week is &quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <a href="http://www.php.net/date" onclick="pageTracker._trackPageview('/outgoing/www.php.net/date?referer=');"><span style="color: #990000;">date</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Y-m-d'</span><span style="color: #339933;">,</span><a href="http://www.php.net/mktime" onclick="pageTracker._trackPageview('/outgoing/www.php.net/mktime?referer=');"><span style="color: #990000;">mktime</span></a><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #000088;">$monthNow</span><span style="color: #339933;">,</span><span style="color: #000088;">$day</span><span style="color: #339933;">,</span><span style="color: #000088;">$yearNow</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/h2&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><em></em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.maggsweb.com/php/first-date-of-the-week/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Classes &#8211; quick example</title>
		<link>http://www.maggsweb.com/uncategorized/php-classes-quick-example/</link>
		<comments>http://www.maggsweb.com/uncategorized/php-classes-quick-example/#comments</comments>
		<pubDate>Wed, 16 Jun 2010 13:04:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.maggsweb.com/?p=938</guid>
		<description><![CDATA[Taken from http://mypaaji.com/Index.php/php-quick-reference/ ?View Code PHP&#60;?php class ClassName&#40;&#41; // class definition &#123; public $var1; // property with public access private $var2; // property with private access &#160; // constructor method public function __construct&#40;&#41; &#123; // code to initialize object goes here &#125; &#160; // public method public function setFoo&#40;$value&#41; &#123; // properties and methods are [...]]]></description>
			<content:encoded><![CDATA[<hr />
Taken from <a href="http://mypaaji.com/Index.php/php-quick-reference/" onclick="pageTracker._trackPageview('/outgoing/mypaaji.com/Index.php/php-quick-reference/?referer=');">http://mypaaji.com/Index.php/php-quick-reference/</a></p>
<hr />
<span id="more-938"></span></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?" onclick="pageTracker._trackPageview('/outgoing/www.ericbess.com/ericblog/2008/03/03/wp-codebox/_examples?referer=');"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p938code8'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p9388"><td class="code" id="p938code8"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> ClassName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// class definition</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$var1</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// property with public access</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$var2</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// property with private access</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// constructor method</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// code to initialize object goes here</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// public method</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setFoo<span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// properties and methods are accessed inside the class</span>
		<span style="color: #666666; font-style: italic;">// using $this-&gt;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span> <span style="color: #004000;">var2</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// private method</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> bar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// more code goes here</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// destructor method</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __destruct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// clean up code goes here</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ClassName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// create a new instance of the object</span>
<span style="color: #000088;">$c</span><span style="color: #339933;">-&gt;</span> <span style="color: #004000;">var1</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">42</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// properties and methods are accessed using - &gt;</span>
<span style="color: #000088;">$c</span><span style="color: #339933;">-&gt;</span> <span style="color: #004000;">setFoo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Hello World'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.maggsweb.com/uncategorized/php-classes-quick-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To Download and Upload Files Over FTP</title>
		<link>http://www.maggsweb.com/uncategorized/how-to-download-and-upload-files-over-ftp/</link>
		<comments>http://www.maggsweb.com/uncategorized/how-to-download-and-upload-files-over-ftp/#comments</comments>
		<pubDate>Wed, 16 Jun 2010 12:55:34 +0000</pubDate>
		<dc:creator>chris</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ftp]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.maggsweb.com/?p=934</guid>
		<description><![CDATA[Taken from http://mypaaji.com/Index.php/how-to-download-upload-transfer-files-over-ftp/ The below given listing illustrates the process. First, a connection to the FTP server is initialized with a call to ftp_connect(); this function returns a connection handle that is used in all subsequent calls. The ftp_login() function is then used to log in to the server, while the ftp_close() function is used [...]]]></description>
			<content:encoded><![CDATA[<hr />
Taken from <a href="http://mypaaji.com/Index.php/how-to-download-upload-transfer-files-over-ftp/" onclick="pageTracker._trackPageview('/outgoing/mypaaji.com/Index.php/how-to-download-upload-transfer-files-over-ftp/?referer=');">http://mypaaji.com/Index.php/how-to-download-upload-transfer-files-over-ftp/</a></p>
<hr />
The below given listing illustrates the process. First, a connection to the FTP server is initialized with a call to ftp_connect();  this function returns a connection handle that is used in all subsequent calls. The ftp_login() function is then used to log in to the server, while the ftp_close()  function is used to terminate the connection and end the session. Between the calls to ftp_connect() and ftp_disconnect(), it is possible to perform all the actions commonly associated with an FTP session.</p>
<p>The below given listing illustrates four of the most common: listing files using ftp_nlist(); uploading files with ftp_put(); downloading files with ftp_get(); and deleting files with ftp_delete(). Note that ftp_put() and ftp_get() must be supplied with the remote and local file name, together with the transfer type (binary or ASCII).</p>
<p><span id="more-934"></span></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?" onclick="pageTracker._trackPageview('/outgoing/www.ericbess.com/ericblog/2008/03/03/wp-codebox/_examples?referer=');"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p934code10'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p93410"><td class="code" id="p934code10"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// set access parameters</span>
<span style="color: #000088;">$host</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ftp.domain.dom&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;user&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pass</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;password&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dir</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/htdocs&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// open connection to FTP server</span>
<span style="color: #000088;">$conn</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/ftp_connect" onclick="pageTracker._trackPageview('/outgoing/www.php.net/ftp_connect?referer=');"><span style="color: #990000;">ftp_connect</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$host</span><span style="color: #009900;">&#41;</span> or <a href="http://www.php.net/die" onclick="pageTracker._trackPageview('/outgoing/www.php.net/die?referer=');"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ERROR: Cannot connect&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// log in</span>
<a href="http://www.php.net/ftp_login" onclick="pageTracker._trackPageview('/outgoing/www.php.net/ftp_login?referer=');"><span style="color: #990000;">ftp_login</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$conn</span><span style="color: #339933;">,</span> <span style="color: #000088;">$user</span><span style="color: #339933;">,</span> <span style="color: #000088;">$pass</span><span style="color: #009900;">&#41;</span> or <a href="http://www.php.net/die" onclick="pageTracker._trackPageview('/outgoing/www.php.net/die?referer=');"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ERROR: Cannot log in&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// get file listing</span>
<span style="color: #000088;">$list</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/ftp_nlist" onclick="pageTracker._trackPageview('/outgoing/www.php.net/ftp_nlist?referer=');"><span style="color: #990000;">ftp_nlist</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$conn</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span> or <a href="http://www.php.net/die" onclick="pageTracker._trackPageview('/outgoing/www.php.net/die?referer=');"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ERROR: Cannot list files&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$list</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$file</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Download a file</span>
<span style="color: #000088;">$remote</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;code.zip&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$local</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;code_sny.zip&quot;</span><span style="color: #339933;">;</span>
<a href="http://www.php.net/ftp_get" onclick="pageTracker._trackPageview('/outgoing/www.php.net/ftp_get?referer=');"><span style="color: #990000;">ftp_get</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$conn</span><span style="color: #339933;">,</span> <span style="color: #000088;">$local</span><span style="color: #339933;">,</span> <span style="color: #000088;">$remote</span><span style="color: #339933;">,</span> FTP_BINARY<span style="color: #009900;">&#41;</span> or <a href="http://www.php.net/die" onclick="pageTracker._trackPageview('/outgoing/www.php.net/die?referer=');"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ERROR: Cannot download file: <span style="color: #006699; font-weight: bold;">$remote</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;File [<span style="color: #006699; font-weight: bold;">$remote</span>] successfully downloaded as [<span style="color: #006699; font-weight: bold;">$local</span>]&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Upload a file</span>
<span style="color: #000088;">$local</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;photoSny.jpg&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$remote</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;photoSny.jpg&quot;</span><span style="color: #339933;">;</span>
<a href="http://www.php.net/ftp_put" onclick="pageTracker._trackPageview('/outgoing/www.php.net/ftp_put?referer=');"><span style="color: #990000;">ftp_put</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$conn</span><span style="color: #339933;">,</span> <span style="color: #000088;">$remote</span><span style="color: #339933;">,</span> <span style="color: #000088;">$local</span><span style="color: #339933;">,</span> FTP_BINARY<span style="color: #009900;">&#41;</span> or <a href="http://www.php.net/die" onclick="pageTracker._trackPageview('/outgoing/www.php.net/die?referer=');"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ERROR: Cannot upload file: <span style="color: #006699; font-weight: bold;">$local</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;File [<span style="color: #006699; font-weight: bold;">$local</span>] successfully uploaded as [<span style="color: #006699; font-weight: bold;">$remote</span>]&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Delete a file</span>
<span style="color: #000088;">$remote</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;someFile.tmp&quot;</span><span style="color: #339933;">;</span>
<a href="http://www.php.net/ftp_delete" onclick="pageTracker._trackPageview('/outgoing/www.php.net/ftp_delete?referer=');"><span style="color: #990000;">ftp_delete</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$conn</span><span style="color: #339933;">,</span> <span style="color: #000088;">$remote</span><span style="color: #009900;">&#41;</span> or <a href="http://www.php.net/die" onclick="pageTracker._trackPageview('/outgoing/www.php.net/die?referer=');"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ERROR: Cannot delete file: <span style="color: #006699; font-weight: bold;">$remote</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;File [<span style="color: #006699; font-weight: bold;">$remote</span>] successfully deleted&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Disconnect</span>
<a href="http://www.php.net/ftp_close" onclick="pageTracker._trackPageview('/outgoing/www.php.net/ftp_close?referer=');"><span style="color: #990000;">ftp_close</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$conn</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.maggsweb.com/uncategorized/how-to-download-and-upload-files-over-ftp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Display filesizes</title>
		<link>http://www.maggsweb.com/javascript/display-filesizes/</link>
		<comments>http://www.maggsweb.com/javascript/display-filesizes/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 08:26:40 +0000</pubDate>
		<dc:creator>chris</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[function]]></category>

		<guid isPermaLink="false">http://www.maggsweb.com/?p=767</guid>
		<description><![CDATA[Ever clicked a link only to find out that the image/download was massive and you wished you hadn&#8217;t? Wouldn&#8217;t it have been nice to have an idea of the file-size when hovering over the link? ?View Code JAVASCRIPT&#160; function byteConvert(num) { var result = 0; var unit = &#34;&#34;; &#160; // Set unit variables for [...]]]></description>
			<content:encoded><![CDATA[<p>Ever clicked a link only to find out that the image/download was massive and you wished you hadn&#8217;t?  Wouldn&#8217;t it have been nice to have an idea of the file-size when hovering over the link?<br />
<span id="more-767"></span></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?" onclick="pageTracker._trackPageview('/outgoing/www.ericbess.com/ericblog/2008/03/03/wp-codebox/_examples?referer=');"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p767code12'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p76712"><td class="code" id="p767code12"><pre class="javascript" style="font-family:monospace;">&nbsp;
function byteConvert(num) {
	var result = 0;
	var unit = &quot;&quot;;
&nbsp;
	// Set unit variables for convenience
	var bytes = 1;
	var kb = 1024;
	var mb = 1048576;
	var gb = 1073741824;
&nbsp;
	// Check for non-numeric or negative num argument
	if (not isNumeric(num) OR num LT 0)
		return &quot;Invalid size argument&quot;;
&nbsp;
	// Check to see if unit was passed in, and if it is valid
	if ((ArrayLen(Arguments) GT 1)
		AND (&quot;bytes,KB,MB,GB&quot; contains Arguments[2]))
	{
		unit = Arguments[2];
	// If not, set unit depending on the size of num
	} else {
		  if      (num lt kb) {	unit =&quot;bytes&quot;;
		} else if (num lt mb) {	unit =&quot;KB&quot;;
		} else if (num lt gb) {	unit =&quot;MB&quot;;
		} else                {	unit =&quot;GB&quot;;
		}		
	}
&nbsp;
	// Find the result by dividing num by the number represented by the unit
	result = num / Evaluate(unit);
&nbsp;
	// Format the result
	if (result lt 10)
	{
		result = NumberFormat(Round(result * 100) / 100,&quot;0.00&quot;);
	} else if (result lt 100) {
		result = NumberFormat(Round(result * 10) / 10,&quot;90.0&quot;);
	} else {
		result = Round(result);
	}
	// Concatenate result and unit together for the return value
	return (result &amp; &quot; &quot; &amp; unit);
}</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.maggsweb.com/javascript/display-filesizes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>English Ordinals for dates in PHP</title>
		<link>http://www.maggsweb.com/php/english_ordinals_for_dates/</link>
		<comments>http://www.maggsweb.com/php/english_ordinals_for_dates/#comments</comments>
		<pubDate>Fri, 27 Nov 2009 08:07:20 +0000</pubDate>
		<dc:creator>chris</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[function]]></category>

		<guid isPermaLink="false">http://www.maggsweb.com/?p=396</guid>
		<description><![CDATA[Displaying the day-part of the date, followed by the month etc. just looks plain wrong and lazy &#8211; &#8217;20 September 2009&#8242;. &#8217;20th&#8217; would look much nicer and can be achieved without too much hard work. A simple function&#8230; ?View Code PHP&#160; &#60;?php function dispDay&#40;$i&#41; &#123; switch&#40; floor&#40;$i/10&#41; % 10 &#41; &#123; default: switch&#40; $i % [...]]]></description>
			<content:encoded><![CDATA[<p>Displaying the day-part of the date, followed by the month etc. just looks plain wrong and lazy &#8211; &#8217;20 September 2009&#8242;.   &#8217;20th&#8217; would look much nicer and can be achieved without too much hard work.  A simple function&#8230;<br />
<span id="more-396"></span></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?" onclick="pageTracker._trackPageview('/outgoing/www.ericbess.com/ericblog/2008/03/03/wp-codebox/_examples?referer=');"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p396code14'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p39614"><td class="code" id="p396code14"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
    <span style="color: #000000; font-weight: bold;">function</span> dispDay<span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span> <a href="http://www.php.net/floor" onclick="pageTracker._trackPageview('/outgoing/www.php.net/floor?referer=');"><span style="color: #990000;">floor</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">%</span> <span style="color: #cc66cc;">10</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
                <span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">%</span> <span style="color: #cc66cc;">10</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">:</span> <span style="color: #000088;">$ordinal</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'st'</span><span style="color: #339933;">;</span>
                    <span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">:</span> <span style="color: #000088;">$ordinal</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'nd'</span><span style="color: #339933;">;</span>
                    <span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">:</span> <span style="color: #000088;">$ordinal</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'rd'</span><span style="color: #339933;">;</span>   
                <span style="color: #009900;">&#125;</span>
            <span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">:</span> <span style="color: #000088;">$ordinal</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'th'</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$i</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;sup&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$ordinal</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/sup&gt;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.maggsweb.com/php/english_ordinals_for_dates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Formatting the time, Twitter Style</title>
		<link>http://www.maggsweb.com/php/formatting-the-time-twitter-style/</link>
		<comments>http://www.maggsweb.com/php/formatting-the-time-twitter-style/#comments</comments>
		<pubDate>Thu, 17 Sep 2009 13:20:55 +0000</pubDate>
		<dc:creator>chris</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[function]]></category>

		<guid isPermaLink="false">http://tech.maggsweb.co.uk/?p=295</guid>
		<description><![CDATA[This has got to be the most self-explanatory, most obvious, but coolest function ever! ?View Code PHP&#60;?php function niceTime&#40;$time&#41; &#123; $delta = time&#40;&#41; - $time; if &#40;$delta &#60; 60&#41; &#123; return 'less than a minute ago.'; &#125; else if &#40;$delta &#60; 120&#41; &#123; return 'about a minute ago.'; &#125; else if &#40;$delta &#60; &#40;45 * [...]]]></description>
			<content:encoded><![CDATA[<p>This has got to be the most self-explanatory, most obvious, but coolest function ever!<br />
<span id="more-295"></span></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?" onclick="pageTracker._trackPageview('/outgoing/www.ericbess.com/ericblog/2008/03/03/wp-codebox/_examples?referer=');"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p295code16'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p29516"><td class="code" id="p295code16"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> niceTime<span style="color: #009900;">&#40;</span><span style="color: #000088;">$time</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$delta</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/time" onclick="pageTracker._trackPageview('/outgoing/www.php.net/time?referer=');"><span style="color: #990000;">time</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$time</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$delta</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">60</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'less than a minute ago.'</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$delta</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">120</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'about a minute ago.'</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$delta</span> <span style="color: #339933;">&lt;</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">45</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">60</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <a href="http://www.php.net/floor" onclick="pageTracker._trackPageview('/outgoing/www.php.net/floor?referer=');"><span style="color: #990000;">floor</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$delta</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">60</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' minutes ago.'</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$delta</span> <span style="color: #339933;">&lt;</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">90</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">60</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'about an hour ago.'</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$delta</span> <span style="color: #339933;">&lt;</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">24</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">60</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">60</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'about '</span> <span style="color: #339933;">.</span> <a href="http://www.php.net/floor" onclick="pageTracker._trackPageview('/outgoing/www.php.net/floor?referer=');"><span style="color: #990000;">floor</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$delta</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">3600</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' hours ago.'</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$delta</span> <span style="color: #339933;">&lt;</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">48</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">60</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">60</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'1 day ago.'</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <a href="http://www.php.net/floor" onclick="pageTracker._trackPageview('/outgoing/www.php.net/floor?referer=');"><span style="color: #990000;">floor</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$delta</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">86400</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' days ago.'</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.maggsweb.com/php/formatting-the-time-twitter-style/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Debugging variables, GET, POST, SESSION, SERVER, ENV</title>
		<link>http://www.maggsweb.com/php/debugging-variables/</link>
		<comments>http://www.maggsweb.com/php/debugging-variables/#comments</comments>
		<pubDate>Fri, 03 Jul 2009 20:14:40 +0000</pubDate>
		<dc:creator>chris</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[function]]></category>

		<guid isPermaLink="false">http://tech.maggsweb.co.uk/?p=245</guid>
		<description><![CDATA[I usually write my own vars out to the screen for debugging using &#8216;print_r($_SESSION)&#8217;,'print_r($_POST)&#8217;etc inside &#60;pre&#62; tags, but this is awesome! (a little too much even). It&#8217;s like phpinfo(), but for your webpage! ?View Code PHP&#60;?php function variable_array_dump&#40;$VARIABLE_NAME, $VARIABLE_ARRAY&#41;&#123; if &#40;is_array&#40;$VARIABLE_ARRAY&#41;&#41; &#123; $output = &#34;&#60;table border='1'&#62;&#34;; $output .= &#34;&#60;head&#62;&#60;tr&#62;&#60;td&#62;&#60;b&#62;&#34; . $VARIABLE_NAME . &#34;&#60;/b&#62;&#60;/td&#62;&#60;td&#62;&#60;b&#62;VALUE&#60;/b&#62;&#60;/td&#62;&#60;/tr&#62;&#60;/head&#62;&#60;body&#62;&#34;; foreach &#40;$VARIABLE_ARRAY [...]]]></description>
			<content:encoded><![CDATA[<p>I usually write my own vars out to the screen for debugging using &#8216;print_r($_SESSION)&#8217;,'print_r($_POST)&#8217;etc inside &lt;pre&gt; tags, but this is awesome! (a little too much even).  It&#8217;s like phpinfo(), but for your webpage!<br />
<span id="more-245"></span></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?" onclick="pageTracker._trackPageview('/outgoing/www.ericbess.com/ericblog/2008/03/03/wp-codebox/_examples?referer=');"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p245code19'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p24519"><td class="code" id="p245code19"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> variable_array_dump<span style="color: #009900;">&#40;</span><span style="color: #000088;">$VARIABLE_NAME</span><span style="color: #339933;">,</span> <span style="color: #000088;">$VARIABLE_ARRAY</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/is_array" onclick="pageTracker._trackPageview('/outgoing/www.php.net/is_array?referer=');"><span style="color: #990000;">is_array</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$VARIABLE_ARRAY</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$output</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;table border='1'&gt;&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;head&gt;&lt;tr&gt;&lt;td&gt;&lt;b&gt;&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$VARIABLE_NAME</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;VALUE&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/head&gt;&lt;body&gt;&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$VARIABLE_ARRAY</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> variable_array_dump<span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;tr&gt;&lt;td&gt;<span style="color: #006699; font-weight: bold;">$key</span>&lt;/td&gt;&lt;td&gt;<span style="color: #006699; font-weight: bold;">$value</span>&lt;/td&gt;&lt;/tr&gt;&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;/body&gt;&lt;/table&gt;&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">return</span> <span style="color: #000088;">$output</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><span style="color: #b1b100;">return</span> <a href="http://www.php.net/strval" onclick="pageTracker._trackPageview('/outgoing/www.php.net/strval?referer=');"><span style="color: #990000;">strval</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$VARIABLE_ARRAY</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">echo</span> variable_array_dump<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'GLOBAL SERVER'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> variable_array_dump<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'GLOBAL ENV'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_ENV</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> variable_array_dump<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'GLOBAL REQUEST'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> variable_array_dump<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'GLOBAL GET'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> variable_array_dump<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'GLOBAL POST'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> variable_array_dump<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'GLOBAL COOKIE'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_COOKIE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>If you want a simpler version, or need to just add something quick, try this:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?" onclick="pageTracker._trackPageview('/outgoing/www.ericbess.com/ericblog/2008/03/03/wp-codebox/_examples?referer=');"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p245code20'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p24520"><td class="code" id="p245code20"><pre class="php" style="font-family:monospace;">&nbsp;
echo '&lt;pre&gt;';
print_r($_GET);
print_r($_POST);
print_r($_SESSION);
echo 'end/pre';</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.maggsweb.com/php/debugging-variables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Image UpLoader</title>
		<link>http://www.maggsweb.com/php/php-image-uploader/</link>
		<comments>http://www.maggsweb.com/php/php-image-uploader/#comments</comments>
		<pubDate>Thu, 18 Oct 2007 10:48:23 +0000</pubDate>
		<dc:creator>chris</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[upload]]></category>

		<guid isPermaLink="false">http://www.cmaggs.co.uk/?p=28</guid>
		<description><![CDATA[My image upload script. Loads of checks, not all used each time. Optional file-physical-size checks rely on &#8216;getimagesize&#8217; working. Its long, but stick with it. It works. ?View Code PHP&#60;?php if &#40;&#40;isset&#40;$_FILES&#91;&#34;txtImage&#34;&#93;&#41;&#41; &#38;&#38; &#40;$_FILES&#91;&#34;txtImage&#34;&#93;&#91;&#34;tmp_name&#34;&#93; != &#34;&#34;&#41;&#41; &#123; if &#40;$_FILES&#91;&#34;txtImage&#34;&#93;&#91;&#34;size&#34;&#93; != 0&#41; &#123; $imageTypes = array&#40;'image/pjpeg'=&#62;'jpg', 'image/jpeg'=&#62;'jpg', 'image/gif'=&#62;'gif', 'image/bmp'=&#62;'bmp', 'image/png'=&#62;'png'&#41;; if &#40;isset&#40;$imageTypes&#91;$_FILES&#91;&#34;txtImage&#34;&#93;&#91;&#34;type&#34;&#93;&#93;&#41;&#41; &#123; if &#40;$_FILES&#91;'txtImage'&#93;&#91;'size'&#93; &#60; [...]]]></description>
			<content:encoded><![CDATA[<p>My image upload script. Loads of checks, not all used each time.  Optional file-physical-size checks rely on &#8216;getimagesize&#8217; working.  Its long, but stick with it.  It works.<br />
<span id="more-28"></span></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?" onclick="pageTracker._trackPageview('/outgoing/www.ericbess.com/ericblog/2008/03/03/wp-codebox/_examples?referer=');"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p28code22'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2822"><td class="code" id="p28code22"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset" onclick="pageTracker._trackPageview('/outgoing/www.php.net/isset?referer=');"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;txtImage&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span>
	  <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;txtImage&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;tmp_name&quot;</span><span style="color: #009900;">&#93;</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: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;txtImage&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;size&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$imageTypes</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array" onclick="pageTracker._trackPageview('/outgoing/www.php.net/array?referer=');"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'image/pjpeg'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'jpg'</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'image/jpeg'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'jpg'</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'image/gif'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'gif'</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'image/bmp'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'bmp'</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'image/png'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'png'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset" onclick="pageTracker._trackPageview('/outgoing/www.php.net/isset?referer=');"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$imageTypes</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;txtImage&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;type&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'txtImage'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'size'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">500000</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #666666; font-style: italic;">//Additional checks for file-physical-size</span>
         <span style="color: #666666; font-style: italic;">//$logo = getimagesize($_FILES[&quot;txtImage&quot;][&quot;tmp_name&quot;]);</span>
         <span style="color: #666666; font-style: italic;">//$maximum = 400;</span>
         <span style="color: #666666; font-style: italic;">//if (($logo[0])&gt;$maximum) {</span>
	 <span style="color: #666666; font-style: italic;">//  $error_image = &quot;ERROR: &quot;.$maximum.&quot;px Width exceeded&quot;;</span>
	 <span style="color: #666666; font-style: italic;">//}</span>
         <span style="color: #666666; font-style: italic;">//if (($logo[1])&gt;$maximum) {</span>
	 <span style="color: #666666; font-style: italic;">//  $error_image = &quot;ERROR: &quot;.$maximum.&quot;px Height exceeded&quot;;</span>
	 <span style="color: #666666; font-style: italic;">//}</span>
	<span style="color: #666666; font-style: italic;">## FILE OK
</span>	<span style="color: #000088;">$disallowed</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array" onclick="pageTracker._trackPageview('/outgoing/www.php.net/array?referer=');"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;@&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;!&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;£&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;$&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;and so on&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$fileName</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/str_replace" onclick="pageTracker._trackPageview('/outgoing/www.php.net/str_replace?referer=');"><span style="color: #990000;">str_replace</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$disallowed</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;_&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'txtImage'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$directory</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;image_uploads/&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">//if(!is_dir($directory)) mkdir($directory,0777);</span>
	<span style="color: #000088;">$destination</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$directory</span><span style="color: #339933;">.</span><span style="color: #000088;">$fileName</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/file_exists" onclick="pageTracker._trackPageview('/outgoing/www.php.net/file_exists?referer=');"><span style="color: #990000;">file_exists</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$destination</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;"># MOVE FILE
</span>
	  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/copy" onclick="pageTracker._trackPageview('/outgoing/www.php.net/copy?referer=');"><span style="color: #990000;">copy</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'txtImage'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tmp_name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$destination</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	  <span style="color: #666666; font-style: italic;">##################
</span>	  <span style="color: #666666; font-style: italic;">###  SUCCESS  ####
</span>	  <span style="color: #666666; font-style: italic;">##################
</span>
	  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$errors</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		   <span style="color: #000088;">$error_image</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ERROR: Cannot save Image&quot;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$errors</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	      	 <span style="color: #000088;">$error_image</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ERROR: Image already exists&quot;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$errors</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	       <span style="color: #000088;">$error_image</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ERROR: File Size exceeds maximum&quot;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$errors</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	     <span style="color: #000088;">$error_image</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ERROR: Image Type not allowed&quot;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$errors</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	   <span style="color: #000088;">$error_image</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ERROR: No Image Filesize&quot;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$errors</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	 <span style="color: #000088;">$error_image</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ERROR: Image Upload Failed&quot;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.maggsweb.com/php/php-image-uploader/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Logging user activity</title>
		<link>http://www.maggsweb.com/php/logging-user-activity/</link>
		<comments>http://www.maggsweb.com/php/logging-user-activity/#comments</comments>
		<pubDate>Wed, 22 Aug 2007 09:33:15 +0000</pubDate>
		<dc:creator>chris</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[log]]></category>

		<guid isPermaLink="false">http://www.cmaggs.co.uk/?p=25</guid>
		<description><![CDATA[Logging user activity is vital when there are multiple authors for a site. It also helps with debugging user activity when there is problems. You certainly don&#8217;t want to be putting this into a database, so the next best thing is a nice little text file. I have used this to log user activity in [...]]]></description>
			<content:encoded><![CDATA[<p>Logging user activity is vital when there are multiple authors for a site.  It also helps with debugging user activity when there is problems.  You certainly don&#8217;t want to be putting this into a database, so the next best thing is a nice little text file.<br />
I have used this to log user activity in a number of sites, as it can easily be added after development.  In this example, $PAGE and $pageTitle are set in each page as they are used to determine menu selections, etc.. but these can easily be set manually.<br />
<span id="more-25"></span></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?" onclick="pageTracker._trackPageview('/outgoing/www.ericbess.com/ericblog/2008/03/03/wp-codebox/_examples?referer=');"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p25code24'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2524"><td class="code" id="p25code24"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> add2log<span style="color: #009900;">&#40;</span><span style="color: #000088;">$var1</span><span style="color: #339933;">,</span><span style="color: #000088;">$var2</span><span style="color: #339933;">,</span><span style="color: #000088;">$var3</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$PAGE</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$PageTitle</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;"># create array
</span>    <span style="color: #000088;">$logArray</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array" onclick="pageTracker._trackPageview('/outgoing/www.php.net/array?referer=');"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$logArray</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'loginname'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$logArray</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'accesslevel'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$logArray</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REMOTE_ADDR'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$logArray</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/date" onclick="pageTracker._trackPageview('/outgoing/www.php.net/date?referer=');"><span style="color: #990000;">date</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y-m-d H:i:s&quot;</span><span style="color: #339933;">,</span><a href="http://www.php.net/time" onclick="pageTracker._trackPageview('/outgoing/www.php.net/time?referer=');"><span style="color: #990000;">time</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">3600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$logArray</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$PAGE</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$logArray</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$PageTitle</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$logArray</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$var1</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$logArray</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$var2</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$logArray</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$var3</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;"># create csv from array
</span>    <span style="color: #000088;">$logDetails</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">.</span><a href="http://www.php.net/implode" onclick="pageTracker._trackPageview('/outgoing/www.php.net/implode?referer=');"><span style="color: #990000;">implode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$logArray</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;"># sort dir
</span>    <span style="color: #000088;">$dir</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'DOCUMENT_ROOT'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/../_logs/&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">//if (!is_dir($dir)) mkdir($dir,0777);</span>
    <span style="color: #666666; font-style: italic;">#make filename
</span>    <span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$dir</span><span style="color: #339933;">.</span><a href="http://www.php.net/date" onclick="pageTracker._trackPageview('/outgoing/www.php.net/date?referer=');"><span style="color: #990000;">date</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y-m-d&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/time" onclick="pageTracker._trackPageview('/outgoing/www.php.net/time?referer=');"><span style="color: #990000;">time</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">3600</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;.htm&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">#write to file
</span>    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$file_handle</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/fopen" onclick="pageTracker._trackPageview('/outgoing/www.php.net/fopen?referer=');"><span style="color: #990000;">fopen</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;a&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> 	<span style="color: #000088;">$ERROR</span><span style="color: #339933;">;</span> <a href="http://www.php.net/exit" onclick="pageTracker._trackPageview('/outgoing/www.php.net/exit?referer=');"><span style="color: #990000;">exit</span></a><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/fwrite" onclick="pageTracker._trackPageview('/outgoing/www.php.net/fwrite?referer=');"><span style="color: #990000;">fwrite</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file_handle</span><span style="color: #339933;">,</span> <span style="color: #000088;">$logDetails</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> 	<span style="color: #000088;">$ERROR</span><span style="color: #339933;">;</span> <a href="http://www.php.net/exit" onclick="pageTracker._trackPageview('/outgoing/www.php.net/exit?referer=');"><span style="color: #990000;">exit</span></a><span style="color: #339933;">;</span>
    <a href="http://www.php.net/fclose" onclick="pageTracker._trackPageview('/outgoing/www.php.net/fclose?referer=');"><span style="color: #990000;">fclose</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file_handle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>This creates nice little log files for each day, that can be displayed, exported, imported, searched, etc&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.maggsweb.com/php/logging-user-activity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
