<?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>am i works? &#187; php</title>
	<atom:link href="http://amiworks.co.in/talk/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://amiworks.co.in/talk</link>
	<description>all about my work</description>
	<lastBuildDate>Fri, 02 Dec 2011 09:49:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>PHP5 patch for FunctionList plugin of Notepad + +</title>
		<link>http://amiworks.co.in/talk/php5-patch-for-functionlist-plugin-of-notepad/</link>
		<comments>http://amiworks.co.in/talk/php5-patch-for-functionlist-plugin-of-notepad/#comments</comments>
		<pubDate>Tue, 14 Dec 2010 16:43:32 +0000</pubDate>
		<dc:creator>Amit Kumar Singh</dc:creator>
				<category><![CDATA[how too?]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[functionlist]]></category>
		<category><![CDATA[notepad++]]></category>

		<guid isPermaLink="false">http://amiworks.co.in/talk/?p=365</guid>
		<description><![CDATA[As you may know Notepad++ is my preferred development tool for PHP, and two months back I found FunctionList plugin that shows list of function in a opened PHP file, and it increased my productivity almost immediately. Only drawback was that it showed just function list and not variables. And today I found this neat [...]]]></description>
			<content:encoded><![CDATA[<p>As you may know Notepad++ is my preferred development tool for PHP, and two months back I found <a href="http://sourceforge.net/projects/npp-plugins/files/Function%20List/">FunctionList</a> plugin that shows list of function in a opened PHP file, and it increased my productivity almost immediately.</p>
<p>Only drawback was that it showed just function list and not variables.</p>
<p>And today I found this <a href="http://www.geoffray.be/blog/php/patch-php5-pour-npp-function-list">neat patch of this plugin by Geoffray Warnants</a><em></em> which now makes it even better with icons and also showing variable.</p>
<div style="float: left;">
<p>This is how it looked before</p>
<p><a href="http://amiworks.co.in/talk/wp-content/uploads/2010/12/functionlist-default.png"><img style="background-image: none; margin: 5px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="functionlist-default" src="http://amiworks.co.in/talk/wp-content/uploads/2010/12/functionlist-default.png" border="0" alt="functionlist-default" width="262" height="772" /></a></p>
</div>
<div style="float: left;">
<p>This is how it looks after the patch</p>
<p><a href="http://amiworks.co.in/talk/wp-content/uploads/2010/12/functionlist-php-patched.png"><img style="background-image: none; margin: 5px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="functionlist-php-patched" src="http://amiworks.co.in/talk/wp-content/uploads/2010/12/functionlist-php-patched.png" border="0" alt="functionlist-php-patched" width="262" height="772" /></a></p>
</div>
<p><a href="http://www.geoffray.be/blog/php/patch-php5-pour-npp-function-list">Download the patch here</a> (post is in French, scroll down to download the patch)</p>
<!-- WP Boastful Plugin by WPoets Team --> <div id='boastful'><strong></strong></div><hr style="border-top:black solid 1px" /><a href="http://amiworks.co.in/talk/php5-patch-for-functionlist-plugin-of-notepad/">PHP5 patch for FunctionList plugin of Notepad + +</a> was first posted on December 14, 2010 at 10:13 pm.<br />©2008 "<a href="http://amiworks.co.in/talk">am i works?</a>". <br />]]></content:encoded>
			<wfw:commentRss>http://amiworks.co.in/talk/php5-patch-for-functionlist-plugin-of-notepad/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing PEAR and PHPUnit on WAMP and Windows 7</title>
		<link>http://amiworks.co.in/talk/installing-pear-and-phpunit-on-wamp-and-windows-7/</link>
		<comments>http://amiworks.co.in/talk/installing-pear-and-phpunit-on-wamp-and-windows-7/#comments</comments>
		<pubDate>Sat, 30 Oct 2010 02:51:00 +0000</pubDate>
		<dc:creator>Amit Kumar Singh</dc:creator>
				<category><![CDATA[how too?]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[pear]]></category>
		<category><![CDATA[phpunit]]></category>
		<category><![CDATA[wamp]]></category>

		<guid isPermaLink="false">http://amiworks.co.in/talk/installing-pear-and-phpunit-on-wamp-and-windows-7/</guid>
		<description><![CDATA[In the project that i am currently working on, we decided to use PHPUnit for doing our unit testing, and i found that it was not a straight forward thing to install that I had thought it would be. I had to start by installing Pear, and as soon as i type ‘go-pear’ in command [...]]]></description>
			<content:encoded><![CDATA[<p>    In the project that i am currently working on, we decided to use PHPUnit for doing our unit testing, and i found that it was not a straight forward thing to install that I had thought it would be. I had to start by installing Pear, and as soon as i type ‘go-pear’ in command prompt and pressed enter key I got my first error.</p>
<p>So here are the steps needed to install PEAR and PHPUnit error free on WAMP.</p>
<p>So let’s start with PEAR, please note my Wampserver is installed on drive ‘H’,&#160; substitute it with your own.</p>
<p>  <span id="more-345"></span><br />
<h2>Steps to Install PEAR</h2>
<p>1 ) Locate the &quot;php.ini&quot; file. In my case, I found it at this path:</p>
<pre>H:\wamp\bin\php\php5.3.0\php.ini</pre>
<p>Don&#8217;t use the WAMP system tray icon to edit this file.</p>
<p>2 ) Find the following line:</p>
<pre>;phar.require_hash = On</pre>
<p>3 ) Uncomment the &quot;;phar.require_hash = On&quot; line by removing the semi-colon.</p>
<p>4 ) Change &quot;On&quot; to &quot;Off&quot;.</p>
<pre>phar.require_hash = Off</pre>
<p>5 ) Save the file.</p>
<p>6 ) Now on command prompt type ‘<em>go-pear</em>’</p>
<p>7 ) Select ‘<em>local</em>’ to the question asked.. and follow the instructions.</p>
<p>8 ) Now we need to edit the ‘<em>php.ini</em>’ again to add pear include path. Open ‘<em>php.ini</em>’ that we found in php5.3.0 folder and search for ‘go-pear’, you will see </p>
<pre>;***** Added by go-pear
include_path=&quot;.;H:\wamp\bin\php\php5.3.0\pear&quot; 

;*****</pre>
<p>Copy these three lines and paste it to ‘<em>php.ini</em>’ file which is located at : </p>
<pre>H:\wamp\bin\apache\apache2.2.11\bin </pre>
<p>9 ) Restart the apache, and you have PEAR installed on you machine.</p>
<p>But we are not done yet, to use ‘pear’ command in your command prompt from anywhere you will need to modify the windows environment variables. </p>
<p>10 ) Go to <em>control panel –&gt; system</em>&#160; and click on the ‘<em>advanced system settings</em>’ (it is on the left sidebar)</p>
<p>11 ) Click on the environment variables button and <em>new/edit</em> ‘PATH’ variable and add&#160; </p>
<pre>‘H:\wamp\bin\php\php5.3.0’</pre>
<p>in your path. You also need to add a new variable ‘PHP_PEAR_PHP_BIN’ and set the value to </p>
<pre>‘H:\wamp\bin\php\php5.3.0\php.exe’</pre>
<p>close you command prompt and open it again for these changes to take effect.</p>
<p>12 ) now type ‘<em>pear’</em> on the command prompt and you should see pear command help printed for you.</p>
<p>Now that PEAR is installed, let’s install the PHPUnit.</p>
<div style="margin: 10px; background: #ffffcc; font-size: 1.2em; font-weight: bold; border: #aaaaaa 1px solid; padding: 5px;">Check out PHPCamp a place to share news, views and articles that are useful to <a style="color: #008888; text-decoration: underline;" title="PHP community where you learn something new every day " href="http://phpcamp.net/?utm_medium=blog_post&amp;utm_source=amiworks_co_in&amp;utm_campaign=pear_phpunit_win7">PHP community</a>.</div>
<h2>Steps to install PHPUnit</h2>
<p>1 ) On ‘C’ drive create a folder named ‘php5’</p>
<p>2 )Then on command prompt type:</p>
<pre> pear upgrade pear</pre>
<p>2 ) Once PEAR&#160; is updated, on command prompt type:</p>
<pre> pear channel-discover components.ez.no 

 pear channel-discover pear.phpunit.de

 pear channel-discover pear.symfony-project.com</pre>
<p>4 )Finally type: </p>
<pre> pear install --alldeps phpunit/PHPUnit</pre>
<p>And with this you should have PHPUnit installed on your system. </p>
<p>In my quest to install PHPUnit I found help from following articles</p>
<ol>
<li><a href="http://stackoverflow.com/questions/1652941/why-am-i-receiving-an-error-when-installing-pear">Stackoverflow</a></li>
<li><a href="http://www.wampserver.com/phorum/read.php?2,67257">Wampserver forum</a></li>
<li><a href="http://usingzendframework.blogspot.com/2007/12/setting-up-phpunit.html">Using Zend Framework blog</a></li>
</ol>
<!-- WP Boastful Plugin by WPoets Team --> <div id='boastful'><strong></strong></div><hr style="border-top:black solid 1px" /><a href="http://amiworks.co.in/talk/installing-pear-and-phpunit-on-wamp-and-windows-7/">Installing PEAR and PHPUnit on WAMP and Windows 7</a> was first posted on October 30, 2010 at 8:21 am.<br />©2008 "<a href="http://amiworks.co.in/talk">am i works?</a>". <br />]]></content:encoded>
			<wfw:commentRss>http://amiworks.co.in/talk/installing-pear-and-phpunit-on-wamp-and-windows-7/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>Simple Way To Add Global Exception Handling In CodeIgniter</title>
		<link>http://amiworks.co.in/talk/simple-way-to-add-global-exception-handling-in-codeigniter/</link>
		<comments>http://amiworks.co.in/talk/simple-way-to-add-global-exception-handling-in-codeigniter/#comments</comments>
		<pubDate>Sat, 02 Oct 2010 13:28:40 +0000</pubDate>
		<dc:creator>Amit Kumar Singh</dc:creator>
				<category><![CDATA[how too?]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[exception handling]]></category>

		<guid isPermaLink="false">http://amiworks.co.in/talk/?p=338</guid>
		<description><![CDATA[I am working on a project where we needed to capture exceptions at a global level instead of doing it at every step as they were not critical, but important for us to know. The idea was that whenever such an exception occur on production we should send an email to developers mailing list so [...]]]></description>
			<content:encoded><![CDATA[<p>I am working on a project where we needed to capture exceptions at a global level instead of doing it at every step as they were not critical, but important for us to know.</p>
<p>The idea was that whenever such an exception occur on production we should send an email to developers mailing list so that someone can investigate it.</p>
<p>As usual I did a quick google search and i found <a href="http://codeigniter.com/forums/viewthread/141573/">two</a> <a href="http://codeigniter.com/forums/viewthread/126752/">forum</a> posts in CodeIgniter and <a href="http://stackoverflow.com/questions/260597/in-codeigniter-how-can-i-have-php-error-messages-emailed-to-me">one</a> on stackoverflow, but they all fall short as CodeIgniter does not set’s any default exception handlers they way it sets the native error handler.</p>
<p>So here is a quick tutorial on how you can do that.<br />
<span id="more-338"></span><br />
First of all you need to setup a hook, so put following code in <em>hook.php</em> file in config folder.</p>
<pre>$hook['pre_controller'][] = array(
                   'class'    =&gt; 'ExceptionHook',
                   'function' =&gt; 'SetExceptionHandler',
                   'filename' =&gt; 'ExceptionHook.php',
                   'filepath' =&gt; 'hooks'
                  );</pre>
<p>Now I am using <em>pre_controller</em> hook as I wanted to use $CI object which is available at this stage.</p>
<p>Now put the code shown below in the file named <em>ExceptionHook.php</em> in your application’s <em>hooks</em> folder.</p>
<p><script src="http://gist.github.com/607550.js?file=ExceptionHook.php"></script> </p>
<p>Also if you need to capture and email native PHP errors, you can do so by extending the Exceptions library as shown in the code below.</p>
<p><script src="http://gist.github.com/607550.js?file=MY_Exceptions.php"></script></p>
<p>While I have used the simple PHP mail function in the example above, you can use CI&#8217;s mail library as well. </p>
<p>If you have any doubts feel free to ask in comments below.</p>
<!-- WP Boastful Plugin by WPoets Team --> <div id='boastful'><strong></strong></div><hr style="border-top:black solid 1px" /><a href="http://amiworks.co.in/talk/simple-way-to-add-global-exception-handling-in-codeigniter/">Simple Way To Add Global Exception Handling In CodeIgniter</a> was first posted on October 2, 2010 at 6:58 pm.<br />©2008 "<a href="http://amiworks.co.in/talk">am i works?</a>". <br />]]></content:encoded>
			<wfw:commentRss>http://amiworks.co.in/talk/simple-way-to-add-global-exception-handling-in-codeigniter/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>CodeIgniter 2.0 Is Baking</title>
		<link>http://amiworks.co.in/talk/codeigniter-2-0-is-baking/</link>
		<comments>http://amiworks.co.in/talk/codeigniter-2-0-is-baking/#comments</comments>
		<pubDate>Fri, 12 Mar 2010 06:48:30 +0000</pubDate>
		<dc:creator>Amit Kumar Singh</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[codeigniter 2.0]]></category>

		<guid isPermaLink="false">http://amiworks.co.in/talk/codeigniter-2-0-is-baking/</guid>
		<description><![CDATA[Just when I was loosing all hopes about CodeIgniter, yesterday EllisLab announced about their move to assembla and mercurial, in that there was a small but significant news about CodeIgniter 2.0. A quick look into the change log revealed PHP 4 support is deprecated. Features new to 2.0.0 may not be support PHP 4, and [...]]]></description>
			<content:encoded><![CDATA[<p>Just when I was loosing all hopes about CodeIgniter, yesterday EllisLab <a href="http://codeigniter.com/news/ellislab_moves_to_mercurial_assembla_bitbucket_codeigniter_2.0_baking/">announced</a> about their move to assembla and mercurial, in that there was a small but significant news about CodeIgniter 2.0.</p>
<p>A quick look into the <a href="http://bitbucket.org/ellislab/codeigniter/src/tip/user_guide/changelog.html">change log</a> revealed</p>
<pre>PHP 4 support is deprecated.  Features new to 2.0.0 may not be support PHP 4, and all legacy features will no longer support PHP 4 as of 2.1.0.</pre>
<p>This is what I was waiting for. What it means, as pointed by <a href="http://philsturgeon.co.uk/news/2010/03/codeigniter-2">Phil Sturgeon</a> and <a href="http://www.haughin.com/2010/03/11/codeigniter-2-critical-changes-implications/">Elliot Haughin</a>, is that CI 2.0 will not run on PHP 4, but more importantly, it can now take full advantages of PHP 5.</p>
<p>One other thing that I liked is</p>
<pre>Added ability to set &quot;Package&quot; paths - specific paths where the Loader and Config classes should try to look first for a requested file.  This allows distribution of sub-applications with their own libraries, models, config files, etc. in a single &quot;package&quot; directory.  </pre>
<p>Which means that now we can create common area where we can keep helpers, views and libraries that needs to be shared between two applications. </p>
<p>While there are many more updates these two got me excited. </p>
<p>For now let’s wait for them to release, meanwhile you can sign up for Bitbucket and follow the updates for <a href="http://bitbucket.org/ellislab/codeigniter/">CodeIgniter Project</a>.</p>
<!-- WP Boastful Plugin by WPoets Team --> <div id='boastful'><strong></strong></div><hr style="border-top:black solid 1px" /><a href="http://amiworks.co.in/talk/codeigniter-2-0-is-baking/">CodeIgniter 2.0 Is Baking</a> was first posted on March 12, 2010 at 12:18 pm.<br />©2008 "<a href="http://amiworks.co.in/talk">am i works?</a>". <br />]]></content:encoded>
			<wfw:commentRss>http://amiworks.co.in/talk/codeigniter-2-0-is-baking/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>How to get Latitude/Longitude from an address (or Geocoding ) using PHP</title>
		<link>http://amiworks.co.in/talk/how-to-get-latitudelongitude-from-an-address-or-geocoding-using-php/</link>
		<comments>http://amiworks.co.in/talk/how-to-get-latitudelongitude-from-an-address-or-geocoding-using-php/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 10:02:15 +0000</pubDate>
		<dc:creator>Amit Kumar Singh</dc:creator>
				<category><![CDATA[how too?]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://amiworks.co.in/talk/how-to-get-latitudelongitude-from-an-address-or-geocoding-using-php/</guid>
		<description><![CDATA[While Google’s documents for maps API does good job in showing how to get lat/long from an address in JavaScript they do not really show any example of doing the same with PHP. &#160; So to make you life simple here is a small script in PHP that does that. &#160; &#160; $geocode=file_get_contents('http://maps.google.com/maps/api/geocode/json?address=573/1,+Jangli+Maharaj+Road,+Deccan+Gymkhana,+Pune,+Maharashtra,+India&#38;sensor=false'); $output= json_decode($geocode); [...]]]></description>
			<content:encoded><![CDATA[<p>While Google’s documents for maps API does good job in showing how to get lat/long from an address in JavaScript they do not really show any example of doing the same with PHP.</p>
<p>&#160;</p>
<p>So to make you life simple here is a small script in PHP that does that.</p>
<p>&#160;</p>
<p>&#160;</p>
<pre class="code">$geocode=file_get_contents('<a href="http://maps.google.com/maps/api/geocode/json?address=573/1,+Jangli+Maharaj+Road,+Deccan+Gymkhana,+Pune,+Maharashtra,+India&amp;sensor=false');">http://maps.google.com/maps/api/geocode/json?address=573/1,+Jangli+Maharaj+Road,+Deccan+Gymkhana,+Pune,+Maharashtra,+India&amp;sensor=false');</a>

$output= json_decode($geocode);

$lat = $output-&gt;results[0]-&gt;geometry-&gt;location-&gt;lat;
$long = $output-&gt;results[0]-&gt;geometry-&gt;location-&gt;lng;</pre>
<p>&#160;</p>
<p>The line above makes a request to Google maps API. Passes the address, and receives the response in JSON format.</p>
<p>The URL has following options </p>
<pre><a href="http://maps.google.com/maps/api/geocode/output?parameters">http://maps.google.com/maps/api/geocode/<i>output</i>?<i>parameters</a></i></pre>
<p>where <em>output</em> can be 1) JSON or 2) XML </p>
<p>For more details about parameters check out the <a href="http://code.google.com/apis/maps/documentation/geocoding/index.html">Google’s geocoding documentation</a>.</p>
<!-- WP Boastful Plugin by WPoets Team --> <div id='boastful'><strong></strong></div><hr style="border-top:black solid 1px" /><a href="http://amiworks.co.in/talk/how-to-get-latitudelongitude-from-an-address-or-geocoding-using-php/">How to get Latitude/Longitude from an address (or Geocoding ) using PHP</a> was first posted on March 10, 2010 at 3:32 pm.<br />©2008 "<a href="http://amiworks.co.in/talk">am i works?</a>". <br />]]></content:encoded>
			<wfw:commentRss>http://amiworks.co.in/talk/how-to-get-latitudelongitude-from-an-address-or-geocoding-using-php/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Where is MySQL Gone Away?</title>
		<link>http://amiworks.co.in/talk/where-is-mysql-gone-away/</link>
		<comments>http://amiworks.co.in/talk/where-is-mysql-gone-away/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 16:51:09 +0000</pubDate>
		<dc:creator>Amit Kumar Singh</dc:creator>
				<category><![CDATA[how too?]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://amiworks.co.in/talk/?p=316</guid>
		<description><![CDATA[Last Sunday I got to work on a very interesting problem in WordPress which I initially thought could be solved in like 5 mins, but alas it took me almost 7 hours before I found and fixed the problem. Let me describe the problem, I was running a simple xml parsing script whose task was [...]]]></description>
			<content:encoded><![CDATA[<p>Last Sunday I got to work on a very interesting problem in WordPress which I initially thought could be solved in like 5 mins, but alas it took me almost 7 hours before I found and fixed the problem.</p>
<p>Let me describe the problem, I was running a simple xml parsing script whose task was to parse the xml file and insert the content into WordPress database as a post, everything was working fine except the <em>‘INSERT’</em> statement was failing with out any errors. Basically everything would run but nothing would get inserted into database and no errors. We had used the <em>‘wp_insert_post’</em> function in  <em>‘post.php’</em> file to handle the insertion of post, which was returning ‘0’ instead.</p>
<p>After lot’s of time spend checking and cross checking the sql statements for error and PHP code logic, i finally found the problem which was a small kinda cryptic error <strong>‘MySQL server has gone away’ </strong>for every single query that was getting executed in the script.</p>
<p>Well, a quick google search took me to <a title="MySQL server gone away" href="http://dev.mysql.com/doc/refman/5.0/en/gone-away.html">MySQL manual</a> page where it list bunch of possibilities on why the error might be coming.</p>
<p>To me the most logical one were</p>
<ol>
<li>
<ol>
<li>You tried to run a query after closing the connection to the server. This indicates a logic error in the application that should be corrected.</li>
<li>A client application running on a different host does not have the necessary privileges to connect to the MySQL server from that host.</li>
<li>You have encountered a timeout on the server side and the automatic reconnection in the client is disabled (the reconnect flag in the MYSQL structure is equal to 0).</li>
<li>You can also get these errors if you send a query to the server that is incorrect or too large.</li>
<li>You are using a Windows client and the server had dropped the connection (probably because wait_timeout expired) before the command was issued.</li>
</ol>
</li>
</ol>
<p>I investigated each one but it turned out that because a query was taking a bit to long to execute MySQL closed the connection and refused all further request from the client.</p>
<p>So you might be wondering what was the <strong>Solution </strong>to this problem.</p>
<p>Well <a href="http://robsnotebook.com/">Rob of Rob’s notebook</a> had the almost perfect solution for it. He <a href="http://robsnotebook.com/wordpress-mysql-gone-away">created a replacement file for<em> ‘wpdb.php’</em></a> which takes care of this problem, yeah it is temporary and you have to remember to replace this file every time you do an WordPress upgrade but it works.</p>
<p>If you are facing this problem go download it and replace you <em>‘wpdb’</em> file and save yourself some time.</p>
<div style="border-bottom: #aaaaaa 1px solid; border-left: #aaaaaa 1px solid; padding-bottom: 5px; margin: 10px; padding-left: 5px; padding-right: 5px; background: #ffffcc; font-size: 1.4em; border-top: #aaaaaa 1px solid; font-weight: bold; border-right: #aaaaaa 1px solid; padding-top: 5px">Check out <a style="color: #008888; text-decoration: underline" title="PHP community where you learn something new every day " href="http://phpcamp.net/?utm_medium=blog_post&amp;utm_source=new_blog_at_amiworks&amp;utm_campaign=where%20MySQL%20Server%20gone">PHPCamp.net</a> a article sharing website relevant to our own PHP community</div>
<!-- WP Boastful Plugin by WPoets Team --> <div id='boastful'><strong></strong></div><hr style="border-top:black solid 1px" /><a href="http://amiworks.co.in/talk/where-is-mysql-gone-away/">Where is MySQL Gone Away?</a> was first posted on November 11, 2009 at 10:21 pm.<br />©2008 "<a href="http://amiworks.co.in/talk">am i works?</a>". <br />]]></content:encoded>
			<wfw:commentRss>http://amiworks.co.in/talk/where-is-mysql-gone-away/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Integrating With Twitter API In CodeIgniter</title>
		<link>http://amiworks.co.in/talk/integrating-twitter-api-with-codeigniter/</link>
		<comments>http://amiworks.co.in/talk/integrating-twitter-api-with-codeigniter/#comments</comments>
		<pubDate>Thu, 29 Jan 2009 17:27:59 +0000</pubDate>
		<dc:creator>Amit Kumar Singh</dc:creator>
				<category><![CDATA[how too?]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://amiworks.co.in/talk/?p=252</guid>
		<description><![CDATA[I needed to integrate Twitter API in one&#160; of my web applications which uses CodeIgniter framework. &#160; As their is no direct library available in CI for twitter integration, at first go this might look very difficult, but it is really simple. &#160; Here is how you can do it.. First download the&#160; Twitter class [...]]]></description>
			<content:encoded><![CDATA[<p>I needed to integrate Twitter API in one&#160; of my web applications which uses CodeIgniter framework.</p>
<div>&nbsp;</div>
<p>As their is no direct library available in CI for twitter integration, at first go this might look very difficult, but it is really simple. </p>
<div>&nbsp;</div>
<p>Here is how you can do it..</p>
<ol>
<li>First <a title="Twitter API wrapper for PHP" href="http://code.google.com/p/php-twitter/">download the&#160; Twitter class</a> for PHP. </li>
<li>Put the <em>class.twitter.php </em>file in <em>application/libraries</em> folder. </li>
<li>Rename <em>class.twitter.php</em> to <em>twitter.php </em>( to make it compatible with CI naming conventions). </li>
<li>Open twitter.php file and set following variables
  </li>
</ol>
<pre>var $username=’'; //twitter username
var $password=''; // twitter password
var $user_agent=''; //an identifier for twitter preferably email address</pre>
<div style="border-right: rgb(170,170,170) 1px solid; padding-right: 5px; border-top: rgb(170,170,170) 1px solid; padding-left: 5px; font-weight: bold; font-size: 1.4em; background: rgb(255,255,204); padding-bottom: 5px; margin: 10px; border-left: rgb(170,170,170) 1px solid; padding-top: 5px; border-bottom: rgb(170,170,170) 1px solid; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial">Are you satisfied with your knowledge? No, then spent 15 minutes every day on <a title="PHP community where you learn something new every day " style="color: rgb(0,136,136); text-decoration: underline" href="http://phpcamp.net/">PHPCamp.net</a> a knowledge sharing website for our own PHP community</div>
<p>If you have followed these steps your integration is almost complete, now all you need to do is use the twitter library, here is an example to get you started <img src='http://amiworks.co.in/talk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<pre> $this-&gt;load-&gt;library('Twitter');
 $msg=’Just Integrated Twitter with CodeIgniter ’;
 $this-&gt;twitter-&gt;update($msg);</pre>
<p>By the way you can <a href="http://twitter.com/thecancerus">follow me on twitter @thecancerus</a>.</p>
<!-- WP Boastful Plugin by WPoets Team --> <div id='boastful'><strong></strong></div><hr style="border-top:black solid 1px" /><a href="http://amiworks.co.in/talk/integrating-twitter-api-with-codeigniter/">Integrating With Twitter API In CodeIgniter</a> was first posted on January 29, 2009 at 10:57 pm.<br />©2008 "<a href="http://amiworks.co.in/talk">am i works?</a>". <br />]]></content:encoded>
			<wfw:commentRss>http://amiworks.co.in/talk/integrating-twitter-api-with-codeigniter/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Debugging PHP using Xdebug and Notepad++ : Part I</title>
		<link>http://amiworks.co.in/talk/debugging-php-using-xdebug-and-notepad-part-i/</link>
		<comments>http://amiworks.co.in/talk/debugging-php-using-xdebug-and-notepad-part-i/#comments</comments>
		<pubDate>Sun, 25 Jan 2009 17:26:29 +0000</pubDate>
		<dc:creator>Amit Kumar Singh</dc:creator>
				<category><![CDATA[how too?]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[dbgp]]></category>
		<category><![CDATA[debugging php]]></category>
		<category><![CDATA[notepad++]]></category>
		<category><![CDATA[xdebug]]></category>

		<guid isPermaLink="false">http://amiworks.co.in/talk/?p=235</guid>
		<description><![CDATA[I am sure all of you have used ‘echo’ and ‘print_r’ to debug PHP. We all know that this way debugging is hard and you need to remember to remove them from production server. Well, thanks to xdebug you can now debug, and you don’t need expensive or blotted IDE for that, just plain and [...]]]></description>
			<content:encoded><![CDATA[<p>I am sure all of you have used ‘echo’ and ‘print_r’ to debug PHP.</p>
<p>We all know that this way debugging is hard and you need to remember to remove them from production server.</p>
<p>Well, thanks to xdebug you can now debug, and you don’t need expensive or blotted IDE for that, just plain and simple Notepad++ can do the job.<img style="display: inline; margin-left: 0px; margin-right: 0px" title="open php.ini in wamp" src="http://amiworks.co.in/talk/wp-content/uploads/2009/01/wamp-phpini.png" alt="open php.ini in wamp" width="209" height="240" align="right" /></p>
<p>In this post we will setup xdebug and DBGp plugin with Notepad++.</p>
<p>Let’s start by installing xdebug.</p>
<ol>
<li>Download the <a href="http://www.xdebug.org/download.php">latest release of xdebug</a> for PHP version you are using.</li>
<li>Copy xdebug dll file into php’s extension directory, in my case, as I use wamp, it is c:\wamp\php\ext .</li>
<li>Now we need to configure xdebug so that it get recognized by PHP, so open php.ini</li>
<li>Add following at the end of your php.ini file
<pre>[xdebug]
zend_extension_ts="c:/wamp/php/ext/php_xdebug-2.0.3-5.2.5.dll"
xdebug.profiler_output_dir = "c:/wamp/tmp/xdebug"
xdebug.profiler_output_name = "cachegrind.out.%p"
xdebug.profiler_enable = 0
xdebug.profiler_append=0
xdebug.extended_info=1
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.idekey=xdebug
xdebug.remote_log="c:/wamp/tmp/xdebug/xdebug_remot.log"
xdebug.show_exception_trace=0
xdebug.show_local_vars=9
xdebug.show_mem_delta=0
xdebug.trace_format=0</pre>
</li>
<li>Just create a folder ‘xdebug’ in ‘c:\wamp\tmp’ folder.</li>
<li>Finally restart Apache service .</li>
</ol>
<p>With these steps you have, finished xdebug installation, it is configured for profiling application and remote debugging. <a href="http://www.xdebug.org/docs/all_settings">Check documentation</a> to know what all these configuration do, and tweak according to your preference.</p>
<p><span id="more-235"></span></p>
<p>We will now install DBGP plugin for <a href="http://notepad-plus.sourceforge.net/uk/site.htm">Notepad++</a>. Make sure you have latest version of Notepad++ is installed.</p>
<ol>
<li>Download the latest release of <a title="DBGP plugin for notepad++" href="http://sourceforge.net/project/showfiles.php?group_id=189927&amp;package_id=236520">DBGp Plugin</a>.</li>
<li>Unzip and move dbgpPlugin.dll file to plugins folder of your notepad++ installation folder, in my case the path is “C:\Program Files\Notepad++\plugins”.</li>
<li>Check out the readme.txt file, that is bundled with plugin, to make sure we don’t miss anything.</li>
<li>Now open Notepad++, and you should see DBGp option in plugins menu.</li>
</ol>
<p><img style="display: block; float: none; margin-left: auto; margin-right: auto" title="dbgp plugin for notepad++" src="http://amiworks.co.in/talk/wp-content/uploads/2009/01/dbgp-notepad.png" alt="dbgp plugin for notepad++" width="310" height="365" /></p>
<p>Well we are now almost finished with setup, only ting remaining is to configure DBGP to listen to right port and we are done.</p>
<p>Goto “Plugins-&gt;DBGp-&gt;Config” to open the configuration screen of DBGp plugin.</p>
<p><img style="display: block; float: none; margin-left: auto; margin-right: auto" title="DBGp Configuration window" src="http://amiworks.co.in/talk/wp-content/uploads/2009/01/dbgpconfig.png" alt="DBGp Configuration window" width="506" height="454" /></p>
<p>Fill the details as shown in the image above. IDE KEY should be same to the one you specified in php.ini settings above. Click Ok and you are done.</p>
<p>To start debugging just add “?XDEBUG_SESSION_START=session_name” at end of you url. ‘session_name’ could be anything you want to keep.</p>
<div style="background:#FFFFCC;border:1px solid #aaa;font-size: 1.4em;font-weight:bold;margin:10px;padding:5px;">Just launched <a href="http://phpcamp.net/" title="PHP community where you learn something new every day " style="color:#008888; text-decoration: underline;">PHPCamp.net</a> a knowledge sharing website for PHP community</div>
<!-- WP Boastful Plugin by WPoets Team --> <div id='boastful'><strong></strong></div><hr style="border-top:black solid 1px" /><a href="http://amiworks.co.in/talk/debugging-php-using-xdebug-and-notepad-part-i/">Debugging PHP using Xdebug and Notepad++ : Part I</a> was first posted on January 25, 2009 at 10:56 pm.<br />©2008 "<a href="http://amiworks.co.in/talk">am i works?</a>". <br />]]></content:encoded>
			<wfw:commentRss>http://amiworks.co.in/talk/debugging-php-using-xdebug-and-notepad-part-i/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>PHPCamp in Pune Mirror</title>
		<link>http://amiworks.co.in/talk/phpcamp-in-pune-mirror/</link>
		<comments>http://amiworks.co.in/talk/phpcamp-in-pune-mirror/#comments</comments>
		<pubDate>Wed, 03 Sep 2008 07:28:50 +0000</pubDate>
		<dc:creator>Amit Kumar Singh</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[phpcamp]]></category>
		<category><![CDATA[phpcamp pune]]></category>
		<category><![CDATA[phpcamppune08]]></category>

		<guid isPermaLink="false">http://amiworks.co.in/talk/phpcamp-in-pune-mirror/</guid>
		<description><![CDATA[News about PHP and PHPCamp was published in today&#8217;s Pune Mirror. Their is just one mistake though, MySpace[:( ]  is not in PHP. It&#8217;s my mistake, I conveyed the wrong information while disscussing[i still can't figure out from where 'myspace is in php' came to my mind] with reporter, stupid me . I regret not [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/thecancerus/2823669431" title="camping to connect"><img src="http://farm4.static.flickr.com/3222/2823669431_cf9db08574.jpg" alt="camping to connect" /></a></p>
<p>News about PHP and <a href="http://phpcamp.org" title="india is gathering for phpcamp on 20th september">PHPCamp</a> was published in today&#8217;s Pune Mirror.</p>
<p>Their is just one mistake though, MySpace[:( ]  is not in PHP. It&#8217;s my mistake, I conveyed the wrong information while disscussing[i still can't figure out from where 'myspace is in php' came to my mind] with reporter, stupid me <img src='http://amiworks.co.in/talk/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  .</p>
<p>I regret not saying Yahoo Answers or Wikipedia as an example instead of MySpace.</p>
<!-- WP Boastful Plugin by WPoets Team --> <div id='boastful'><strong></strong></div><hr style="border-top:black solid 1px" /><a href="http://amiworks.co.in/talk/phpcamp-in-pune-mirror/">PHPCamp in Pune Mirror</a> was first posted on September 3, 2008 at 7:28 am.<br />©2008 "<a href="http://amiworks.co.in/talk">am i works?</a>". <br />]]></content:encoded>
			<wfw:commentRss>http://amiworks.co.in/talk/phpcamp-in-pune-mirror/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Easy File Uploading Solution For PHP</title>
		<link>http://amiworks.co.in/talk/handling-file-uploads-in-php/</link>
		<comments>http://amiworks.co.in/talk/handling-file-uploads-in-php/#comments</comments>
		<pubDate>Mon, 01 Sep 2008 07:48:21 +0000</pubDate>
		<dc:creator>Amit Kumar Singh</dc:creator>
				<category><![CDATA[how too?]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php file uploads]]></category>
		<category><![CDATA[resizing images in php]]></category>
		<category><![CDATA[simple image uploads]]></category>
		<category><![CDATA[uploading images]]></category>

		<guid isPermaLink="false">http://amiworks.co.in/talk/handling-file-uploads-in-php/</guid>
		<description><![CDATA[Uploading files/images is a task that is required in almost all web applications. While uploading file is a very simple task, still lot of beginners in PHP get stuck in this step. So in this post I decided to share the functions I learned while I was a beginner, and I still continue to use [...]]]></description>
			<content:encoded><![CDATA[<p>Uploading files/images is a task that is required in almost all web applications.</p>
<p>While uploading file is a very simple task, still lot of beginners in PHP get stuck in this step. So in this post I decided to share the functions I learned while I was a beginner, and I still continue to use them because of it&#8217;s simplicity and usefulness.</p>
<p>For all my file uploading needs I use the<em> <a href="http://www.phpclasses.org/browse/package/2181.html" title="class to quickly integrate file upload and image manipulation in your site" target="_blank">class.upload.php</a></em> written by <a href="http://www.verot.net" target="_blank">Colin Verot</a>. Ok, I know all about PHP functions like <em>move_uploaded_file()</em> and <em>is_uploaded_file()<strong>, </strong></em>still I prefer to use <em>class.upload.php</em> file because, this file provides me with good set of image manipulation functions along with a neat way to know when a file has been uploaded.</p>
<p>So, let&#8217;s get started on, how to easily upload a file in PHP.</p>
<p>First, let&#8217;s create a simple HTML form for uploading files.</p>
<pre class="akcode">
 &lt;form action="file-upload.php" method="post" enctype="multipart/form-data"&gt;

  Upload file: &lt;input type="file" name="fileupload"&gt;

                  &lt;input type="submit" value="save"&gt;

 &lt;/form&gt;</pre>
<p>It is important to note that the form&#8217;s <em>enctype</em> is  <em>multipart/form-data. </em>This a place where novice developers make lot&#8217;s of mistake, they will forget to add <em>enctype </em>attribute to form and them spends hours thinking why they are not able to upload files or images.</p>
<p>Now, that we have a form to upload files, let&#8217;s see how we can handle file uploads on server.</p>
<p>I am going to cover four scenario&#8217;s here.</p>
<p><span id="more-148"></span></p>
<h3>Simple File Uploading</h3>
<pre>
 if($_FILES['fileupload']['error']!=4)
 {
   $handle = new Upload($_FILES['fileupload']);
   if ($handle-&gt;uploaded)
   {
     $handle-&gt;Process('images/originalview/');
     // file uploaded do whatever you want to do now.
   }
   else
   {
       echo '  Error: ' . $handle-&gt;error;
   }
 }</pre>
<p>What we are doing above is basically, first testing if &#8216;fileupload&#8217; field in the form is not empty. If it is not empty, then we create an instance of upload class, by passing the $_FILES object.</p>
<p>Then we check if file specified in<em> fileupload</em> field has been successfully uploaded on the server or not.</p>
<p>If it has been uploaded then we move that file from temporary location to folder where we want to store the uploaded file. In our case it is <em>originalview folder in images folder.</em></p>
<p>Now that file is uploaded and moved to server you can store the meta data of the images to database or use it whatever way you want.</p>
<h3>Renaming a File, After Uploading</h3>
<pre>
if($_FILES['fileupload']['error']!=4)
{
  $handle = new Upload($_FILES['fileupload']);
  if ($handle-&gt;uploaded)
  {
     $handle-&gt;file_new_name_body =date('YmdHis');
     $handle-&gt;Process('images/originalview/');
     if ($handle-&gt;processed)
     {
        //file is renamed and stored in images/originalview folder.
     }
   }
   else
   {
      echo '  Error: ' . $handle-&gt;error . '';
   }
}</pre>
<p>Now, simply uploading a file, without renaming it in some sort of way, can result in a file getting overwritten. To avoid this situation it is recommended that you rename the file based at least of date and time of image upload. Off course this is still not a perfect solution to avoid filename conflicts, still we can use this for normal cases.</p>
<p>As shown in the code above, the only difference is that we specify a new body name of the file that we uploaded, before moving it to final destination.</p>
<p>By using <em>processed</em> variable of handle object, we can ensure that file has been successfully renamed.</p>
<h3>Resizing Image After Uploading</h3>
<pre>
if($_FILES['fileupload']['error']!=4)
{
   $handle = new Upload($_FILES['fileupload']);
   if ($handle-&gt;uploaded)
   {
     $file_body =date('YmdHis');
     $handle-&gt;image_resize          = true;
     $handle-&gt;image_ratio        = true;
     $handle-&gt;image_x               = 100;
     $handle-&gt;image_y               = 100;
     $handle-&gt;file_new_name_body =$file_body;
     $handle-&gt;Process("images/thumbnail/");

     $handle-&gt;image_resize          = true;
     $handle-&gt;image_ratio        = true;
     $handle-&gt;image_x               = 150;
     $handle-&gt;image_y               = 150;
     $handle-&gt;file_new_name_body =$file_body;
     $handle-&gt;Process("images/imageview/");
    }
    else
    {
      echo '  Error: ' . $handle-&gt;error . '';
     }
}</pre>
<p>When it comes to file uploading, chances are that the file would be an image file, and we need to resize it, to make sure it fit&#8217;s within the fixed dimensions. Now resizing an image with proper aspect ratio is not an easy job.</p>
<p>But thanks to <em>class.upload.php</em>, it has become a trivial task. As shown in the code above, all you have to do is to set the image_resize and image_ratio property to true and specify the maximum allowed dimensions for the image. All the rest will be taken care by upload class.</p>
<p>Also sometimes it might be necessary to create multiple images of variable sizes even that can be archived easily as show above.</p>
<h3>Handling Multiple File Uploads</h3>
<pre>
 $files = array(); 
foreach ($_FILES['fileupload'] as $k =&gt; $l)
{
    foreach ($l as $i =&gt; $v)
    {
        if (!array_key_exists($i, $files))
        $files[$i] = array();
        $files[$i][$k] = $v;
    }
}</pre>
<p>Sometimes it might be necessary to allow user to upload more then one file to the webserver. In that case we can name all our input fields something similar to &#8220;<em>fileupload[]</em>&#8220;.</p>
<p>Then we can use the logic above to  create an new array out of $_FILES, and then pass that array to upload class as shown below.</p>
<p>I have taken this example directly from the test file provided with <em>class.upload.php.</em></p>
<pre>
 foreach ($files as $file)
 {
    // we instantiate the class for each element of $file 
     $handle = new Upload($file);
   // then we check if the file has been uploaded properly
   // in its *temporary* location in the server (often, it is /tmp)
   if ($handle-&gt;uploaded)
   {
      $handle-&gt;Process("./test/");
      if ($handle-&gt;processed)
      {
         // everything was fine !
      }
      else
      {
         echo '  file not uploaded to the wanted location';
         echo '  Error: ' . $handle-&gt;error . '';
      }
    }
    else
    {
        echo '  Error: ' . $handle-&gt;error . '';
    }
 }</pre>
<p>While I was writing this I found <a href="http://www.gsdesign.ro/blog/how-to-upload-resize-images-in-php-with-thumb-creation/" title="How to upload &amp; resize images in PHP with thumb creation" target="_blank">another article which has covered usage of class.upload.php</a>, you may find it useful.</p>
<p>I think this is the easiest way to handle file uploads in PHP, I would love to know how you used to manage the file uploads and image resizing.</p>
<!-- WP Boastful Plugin by WPoets Team --> <div id='boastful'><strong></strong></div><hr style="border-top:black solid 1px" /><a href="http://amiworks.co.in/talk/handling-file-uploads-in-php/">Easy File Uploading Solution For PHP</a> was first posted on September 1, 2008 at 7:48 am.<br />©2008 "<a href="http://amiworks.co.in/talk">am i works?</a>". <br />]]></content:encoded>
			<wfw:commentRss>http://amiworks.co.in/talk/handling-file-uploads-in-php/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

