<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Nilesh Odedra - PHP Interview Question &#124; Java Interview Question &#124; PHP FAQs &#124; PHP Question-Answer &#124; Java Technical Question</title>
	<atom:link href="http://odedranilesh.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://odedranilesh.wordpress.com</link>
	<description>Nilesh Odedra - PHP Interview Question, Java Interview Question, Question-Answer for PHP &#38; Java, PHP FAQs, Java Technical Question,</description>
	<lastBuildDate>Tue, 17 Jan 2012 11:05:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='odedranilesh.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Nilesh Odedra - PHP Interview Question &#124; Java Interview Question &#124; PHP FAQs &#124; PHP Question-Answer &#124; Java Technical Question</title>
		<link>http://odedranilesh.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://odedranilesh.wordpress.com/osd.xml" title="Nilesh Odedra - PHP Interview Question &#124; Java Interview Question &#124; PHP FAQs &#124; PHP Question-Answer &#124; Java Technical Question" />
	<atom:link rel='hub' href='http://odedranilesh.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Generate Dynamic Cache (Zend Framework)</title>
		<link>http://odedranilesh.wordpress.com/2012/01/17/generate-dynamic-cache-zend-framework/</link>
		<comments>http://odedranilesh.wordpress.com/2012/01/17/generate-dynamic-cache-zend-framework/#comments</comments>
		<pubDate>Tue, 17 Jan 2012 11:05:10 +0000</pubDate>
		<dc:creator>Nilesh Odedra</dc:creator>
				<category><![CDATA[php tutor]]></category>
		<category><![CDATA[Cache]]></category>
		<category><![CDATA[Caching Data]]></category>
		<category><![CDATA[Dynamic Cache]]></category>
		<category><![CDATA[Manage Cache in Zend]]></category>
		<category><![CDATA[Zend Cache]]></category>
		<category><![CDATA[Zend Caching]]></category>
		<category><![CDATA[Zend Dynamic Cache]]></category>

		<guid isPermaLink="false">http://odedranilesh.wordpress.com/?p=148</guid>
		<description><![CDATA[This example is used to create a dynamic cache in zend framework. There are two files used in this example. 1) index.php 2) ManageCache.php &#8220;ManageCache.php&#8221; is the library file for caching. You can use or modify the methods if required. &#8220;index.php&#8221; is the file where we are performing cache related operations like checking, removing and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=odedranilesh.wordpress.com&amp;blog=7292930&amp;post=148&amp;subd=odedranilesh&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>This example is used to create a dynamic cache in zend framework.</strong></p>
<p>There are two files used in this example.</p>
<p>1) index.php<br />
2) ManageCache.php<br />
&#8220;ManageCache.php&#8221; is the library file for caching. You can use or modify the methods if required.<br />
&#8220;index.php&#8221; is the file where we are performing cache related operations like checking, removing and displaying cache information.<br />
Please refer both files in detail before implementing zend caching for dynamic data.</p>
<p><strong>1) ManageCache.php</strong></p>
<p>&lt;?php</p>
<p>class ManageCache<br />
{</p>
<p>// Defining variables<br />
protected static $_cache;<br />
protected $_cache_id;</p>
<p>function __construct($user_id)<br />
{<br />
// Requiring base cache file from zend library and if library was included then no need to write this line of code<br />
require_once &#8216;Zend/Cache.php&#8217;;</p>
<p>// Defining Cache Unique Value<br />
$this-&gt;_cache_id = md5($user_id);</p>
<p>// Loading Default Cache Frontend Settings<br />
$frontendOptions = array(<br />
&#8216;lifetime&#8217;=&gt; 7200,<br />
&#8216;automatic_serialization&#8217; =&gt; true<br />
);</p>
<p>// Loading Default Cache Backend Settings<br />
$backendOptions = array(<br />
&#8216;cache_dir&#8217;=&gt; &#8216;/tmp&#8217;<br />
);</p>
<p>// Checking cache object set or not<br />
if(self::$_cache==null)<br />
{<br />
// Setting Up Zend Cache Factory Options<br />
self::$_cache = Zend_Cache::factory(<br />
&#8216;Core&#8217;,<br />
&#8216;File&#8217;,<br />
$frontendOptions,<br />
$backendOptions<br />
);<br />
}<br />
}</p>
<p>/**<br />
* Check Cache Data.<br />
*<br />
* @param Cache Identifier.<br />
* @return Boolean on false and return unserialize the cache data on success<br />
*/<br />
public function checkCache($identifier=&#8221;)<br />
{<br />
// Resultant Array Data<br />
$resultArray = array();</p>
<p>// Checking and fetching data if cache is set<br />
if(!($resultArray = self::$_cache-&gt;load($this-&gt;_cache_id.$identifier)))<br />
return false;<br />
else<br />
return unserialize($resultArray);<br />
}</p>
<p>/**<br />
* Save Cache Data.<br />
*<br />
* @param Cache Identifier.<br />
* @param Array of data to be serialize and cached.<br />
* @return None<br />
*/<br />
public function saveCache($identifier=&#8221;,$data=array())<br />
{<br />
// Saving Cache data<br />
if(!($resultArray = self::$_cache-&gt;load($this-&gt;_cache_id.$identifier)))<br />
self::$_cache-&gt;save(serialize($data));<br />
}</p>
<p>/**<br />
* Remove Cache Identifier Data.<br />
*<br />
* @param Cache Identifier.<br />
* @return None<br />
*/<br />
public function removeCache($identifier=&#8221;)<br />
{<br />
// Removing Cache Identifier<br />
self::$_cache-&gt;remove($this-&gt;_cache_id.$identifier);<br />
}<br />
}</p>
<p>?&gt;</p>
<p><strong>2) index.php</strong></p>
<p>&lt;?php</p>
<p>// Requiring base Manage cache file<br />
require_once &#8216;ManageCache.php&#8217;;</p>
<p>// Say, I want to create cache for user id ==&gt; 1<br />
$userId = 1;</p>
<p>// Defining base cache object<br />
$objCache = new ManageCache($userId);</p>
<p>// check if the &#8216;myresult&#8217; key is present into the cache<br />
if (!$resultData = $objCache-&gt;checkCache(&#8216;myResultCache&#8217;))<br />
{<br />
// Connect to database and get required data which needs to cache<br />
require_once &#8216;Zend/Db.php&#8217;;<br />
$db = Zend_Db::factory(&#8220;Define Db Connection object&#8221;);<br />
$resultData = $db-&gt;fetchAll(&#8216;SELECT * FROM tablename&#8217;);</p>
<p>// update the cache<br />
$objCache-&gt;saveCache($resultData, &#8216;myResultCache&#8217;);<br />
}</p>
<p>// If you want to remove cache then<br />
$objCache-&gt;removeCache(&#8216;myResultCache&#8217;);</p>
<p>// Get the resultant data<br />
print_r($resultData);</p>
<p>?&gt;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/odedranilesh.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/odedranilesh.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/odedranilesh.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/odedranilesh.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/odedranilesh.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/odedranilesh.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/odedranilesh.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/odedranilesh.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/odedranilesh.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/odedranilesh.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/odedranilesh.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/odedranilesh.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/odedranilesh.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/odedranilesh.wordpress.com/148/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=odedranilesh.wordpress.com&amp;blog=7292930&amp;post=148&amp;subd=odedranilesh&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://odedranilesh.wordpress.com/2012/01/17/generate-dynamic-cache-zend-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/501803e3b68d6d613b93b6f305f877ab?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">odedranilesh</media:title>
		</media:content>
	</item>
		<item>
		<title>Installing Solr</title>
		<link>http://odedranilesh.wordpress.com/2012/01/10/installing-solr/</link>
		<comments>http://odedranilesh.wordpress.com/2012/01/10/installing-solr/#comments</comments>
		<pubDate>Tue, 10 Jan 2012 10:17:12 +0000</pubDate>
		<dc:creator>Nilesh Odedra</dc:creator>
				<category><![CDATA[php tutor]]></category>
		<category><![CDATA[Solr]]></category>
		<category><![CDATA[Install solr on linux]]></category>
		<category><![CDATA[Install Solr on Windows]]></category>
		<category><![CDATA[lucene]]></category>
		<category><![CDATA[PHP Solr]]></category>
		<category><![CDATA[Solr Installation]]></category>
		<category><![CDATA[Solr server]]></category>

		<guid isPermaLink="false">http://odedranilesh.wordpress.com/?p=143</guid>
		<description><![CDATA[Installing solr on linux and windows machine. 1) First check is java installed ? Run below command in you terminal if you are using linux.  cmd : java If you are using windows then check in your program files. C:\Program Files IF NOT INSTALLED, Download it from here… http://www.oracle.com/technetwork/java/javase/downloads/jdk-7u2-download-1377129.html 2) Then we will need to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=odedranilesh.wordpress.com&amp;blog=7292930&amp;post=143&amp;subd=odedranilesh&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong><span style="text-decoration:underline;">Installing solr on linux and windows machine.</span></strong></p>
<p>1) First check is java installed ?</p>
<p><em>Run below command in you terminal if you are using linux.  </em></p>
<p>cmd : java</p>
<p><em>If you are using windows then check in your program files.</em></p>
<p>C:\Program Files</p>
<p>IF NOT INSTALLED, Download it from here…</p>
<p>http://www.oracle.com/technetwork/java/javase/downloads/jdk-7u2-download-1377129.html</p>
<p>2) Then we will need to download apache solr.</p>
<p>Run this command in your terminal to download apache solr online. (Linux)</p>
<p>cmd : wget -i http://apache.mirrors.tds.net//lucene/solr/3.5.0/apache-solr-3.5.0.tgz</p>
<p>You can download it online from here.</p>
<p><a href="http://apache.mirrors.tds.net/lucene/solr/">http://apache.mirrors.tds.net//lucene/solr/</a></p>
<p>It will download apache solr online as zip compressed.</p>
<p>Extract this zip file in your drive.</p>
<p>3) Now we will need <strong>mysql jdbc connector</strong>. You can download it from here:</p>
<p>Url: http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.17.zip/from/http://gd.tuwien.ac.at/db/mysql/</p>
<p>After downloading extract the zip file, you will find &#8216;<strong>mysql-connector-java-5.1.17-bin.jar</strong>&#8216; in this folder.</p>
<p>Copy this file &#8216;mysql-connector-java-5.1.17-bin.jar&#8217; and paste in &#8216;apache-solr-3.5.0/example/lib&#8217; Directory.</p>
<p>4) After that open solr Config.xml from &#8220;apache-solr-3.5.0/example/solr/conf/solrconfig.xml&#8221;</p>
<p>Search for &#8220;A Robust Example&#8221;</p>
<p>Add below lines above the searched text:</p>
<p>&lt;requestHandler name=&#8221;/dataimport&#8221; class=&#8221;org.apache.solr.handler.dataimport.DataImportHandler&#8221;&gt;</p>
<p>&lt;lst name=&#8221;defaults&#8221;&gt;</p>
<p>&lt;str name=&#8221;config&#8221;&gt;data-config.xml&lt;/str&gt;</p>
<p>&lt;/lst&gt;</p>
<p>&lt;/requestHandler&gt;</p>
<p><strong>Save the solrconfig.xml file.</strong></p>
<p>5) Next, create file at following location &#8220;apache-solr-3.5.0/example/solr/conf/&#8221; with the name <strong>&#8216;data-config.xml</strong>&#8216;.</p>
<p>This is for setting DB connection with username, pass and also for importing data. Example data-config.xml.</p>
<p>&lt;!&#8211;  DATA CONFIG FILE EXAMPLE &#8211;&gt;</p>
<p>&lt;dataConfig&gt;</p>
<p>&lt;dataSource type=&#8221;JdbcDataSource&#8221;</p>
<p>driver=&#8221;com.mysql.jdbc.Driver&#8221;</p>
<p>url=&#8221;jdbc:mysql://localhost/&lt;tablename&gt;&#8221;</p>
<p>user=&#8221;root&#8221;</p>
<p>password=&#8221;"/&gt;</p>
<p>&lt;document&gt;</p>
<p>&lt;entity name=&#8221;user_id&#8221;  query=&#8221;select user_id, concat(user_id,&#8217;_',&#8217;user&#8217;)as concatunid,concat(first_name,&#8217; &#8216;,last_name) as name,email_id,&#8217;user&#8217; as category from</p>
<p>tbl_user&#8221;&gt;</p>
<p>&lt;field column=&#8221;concatunid&#8221; name=&#8221;id&#8221;/&gt;</p>
<p>&lt;field column=&#8221;user_id&#8221; name=&#8221;unid_i&#8221;/&gt;</p>
<p>&lt;field column=&#8221;name&#8221; name=&#8221;name&#8221;/&gt;</p>
<p>&lt;field column=&#8221;email_id&#8221; name=&#8221;description&#8221;/&gt;</p>
<p>&lt;field column=&#8221;category&#8221; name=&#8221;category&#8221;/&gt;</p>
<p>&lt;/entity&gt;</p>
<p>&lt;entity name=&#8221;listid&#8221;    query=&#8221;select *,concat(listid,&#8217;_',&#8217;user&#8217;)as concatunid,&#8217;url&#8217; as category from siteurl_list&#8221;&gt;</p>
<p>&lt;field column=&#8221;concatunid&#8221; name=&#8221;id&#8221;/&gt;</p>
<p>&lt;field column=&#8221;listid&#8221; name=&#8221;unid_i&#8221;/&gt;</p>
<p>&lt;field column=&#8221;siteurl&#8221; name=&#8221;name&#8221;/&gt;</p>
<p>&lt;field column=&#8221;category&#8221; name=&#8221;category&#8221;/&gt;</p>
<p>&lt;/entity&gt;</p>
<p>&lt;/document&gt;</p>
<p>&lt;/dataConfig&gt;</p>
<p><em>            Replace </em>&lt;tablename&gt; <em>with your table name.</em></p>
<p>6) If you want to add any new field in &#8220;Schema&#8221; for indexing at solr then you have to make changes at &#8220;apache-solr-3.5.0/example/solr/conf/schema.xml&#8221; file.</p>
<p>Example Changes:</p>
<p>&lt;field name=&#8221;title&#8221; type=&#8221;text&#8221; indexed=&#8221;true&#8221; stored=&#8221;true&#8221; multiValued=&#8221;true&#8221;/&gt;</p>
<p>7) Now that we have installed and done all the required settings, time to run solr</p>
<p>For starting Solr use below command</p>
<p>cd apache-solr-3.5.0/example/</p>
<p>java -jar start.jar //This will start Solr at the server</p>
<p>OR</p>
<p>java -jar start.jar &amp; disown // For Run solr In back ground If we close or exit terminal</p>
<p>You can directly click on the start.jar file.</p>
<p>8) Running Solr on browser use this url at server*</p>
<p>Can replace &#8220;Localhost&#8221; with domain name or IP</p>
<p>Example: http://localhost:8983/solr/</p>
<p>9) Now your solr is up and running&#8230; But if you want to import the fields from your table then</p>
<p>For Importing All DB data at solr according to your data-config.xml</p>
<p>URL: http://localhost:8983/solr/admin/dataimport.jsp?handler=/dataimport</p>
<p>10) For Accessing solr by php use &#8220;Solr-PHP-client&#8221; lib</p>
<p>URL: http://code.google.com/p/solr-php-client/downloads/list</p>
<p>Download PHP Lib url : http://code.google.com/p/solr-php-client/downloads/detail?name=SolrPhpClient.r60.2011-05-04.zip&amp;can=2&amp;q=</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/odedranilesh.wordpress.com/143/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/odedranilesh.wordpress.com/143/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/odedranilesh.wordpress.com/143/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/odedranilesh.wordpress.com/143/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/odedranilesh.wordpress.com/143/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/odedranilesh.wordpress.com/143/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/odedranilesh.wordpress.com/143/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/odedranilesh.wordpress.com/143/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/odedranilesh.wordpress.com/143/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/odedranilesh.wordpress.com/143/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/odedranilesh.wordpress.com/143/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/odedranilesh.wordpress.com/143/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/odedranilesh.wordpress.com/143/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/odedranilesh.wordpress.com/143/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=odedranilesh.wordpress.com&amp;blog=7292930&amp;post=143&amp;subd=odedranilesh&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://odedranilesh.wordpress.com/2012/01/10/installing-solr/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/501803e3b68d6d613b93b6f305f877ab?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">odedranilesh</media:title>
		</media:content>
	</item>
		<item>
		<title>Ajax Image Uploading</title>
		<link>http://odedranilesh.wordpress.com/2011/09/03/ajax-image-uploading/</link>
		<comments>http://odedranilesh.wordpress.com/2011/09/03/ajax-image-uploading/#comments</comments>
		<pubDate>Sat, 03 Sep 2011 10:57:29 +0000</pubDate>
		<dc:creator>Nilesh Odedra</dc:creator>
				<category><![CDATA[Image Manipulation]]></category>
		<category><![CDATA[Ajax image uploading]]></category>
		<category><![CDATA[ajax uploading]]></category>
		<category><![CDATA[imaga ajax upload]]></category>
		<category><![CDATA[Image Upload Ajax]]></category>
		<category><![CDATA[uploading image with ajax]]></category>

		<guid isPermaLink="false">http://odedranilesh.wordpress.com/?p=128</guid>
		<description><![CDATA[// Save this file as index.php // Download jquery.js (Version 1.5.2) and jquery-ui-1.7.min.js (Version 1.8.8) &#60;?php session_start(); ?&#62; &#60;script type="text/javascript" src="js/jquery.js"&#62;&#60;/script&#62; &#60;script type="text/javascript" src="js/jquery-ui-1.7.min.js"&#62;&#60;/script&#62; &#60;script type="text/javascript" src="js/ajaxupload.js"&#62;&#60;/script&#62; &#60;script language="Javascript"&#62; var jquery = $.noConflict(); // This code is used to upload image using ajax. jquery(document).ready(function() { new Ajax_upload('#photo', { action: 'ajax_uploadnew.php', method: 'get', name: 'photo', autoSubmit: [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=odedranilesh.wordpress.com&amp;blog=7292930&amp;post=128&amp;subd=odedranilesh&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<pre>// Save this file as index.php
// Download jquery.js (Version 1.5.2) and jquery-ui-1.7.min.js (Version 1.8.8)
&lt;?php
	session_start();
?&gt;
&lt;script type="text/javascript" src="js/jquery.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="js/jquery-ui-1.7.min.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="js/ajaxupload.js"&gt;&lt;/script&gt;

&lt;script language="Javascript"&gt;
var jquery = $.noConflict();
// This code is used to upload image using ajax.
jquery(document).ready(function() {

	new Ajax_upload('#photo', {
		action: 'ajax_uploadnew.php',
		method: 'get',
		name: 'photo',
		autoSubmit: true,
		responseType: false,
		onChange: function(file, extension) {

			if (extension &amp;&amp; /^(jpg|png|jpeg|gif)$/.test(extension)) {
				jquery('#imageError').text('');
			} else {
		 		document.getElementById("imageError").style.display = 'block';
				jquery('#imageError').text('');
				// Check if image exists in folder then display image otherwise no image picture is displayed.
				document.getElementById('img_preview').src="img/no_image.gif";

				jquery('&lt;div&gt;&lt;/div&gt;').appendTo(jquery('#imageError')).text('Error: Only images are allowed with extension jpg, png, gif');
				//jquery('&lt;div&gt;&lt;/div&gt;').appendTo(jquery('#imageError')).text('Format Supported: jpg, png, gif');
				return false;
			}
		},
		onSubmit: function(file, extension) {
			jquery('#loading_img').show();
			this.setData({'img_name':file
			});
		},
		onComplete : function(file, response) {

			// Check if the response message is error then display error message
			if(response == 'size_error') {
				document.getElementById('imageError').innerHTML = 'Upload image with size less then 1000 x 1000 pixel.';
				jquery('#loading_img').hide();
			} else {

				document.getElementById("img_preview_delete").style.display = 'block';
				document.getElementById("img_preview").style.display = 'block';
				document.getElementById("img_delete").style.display = 'block';

				document.getElementById("img_name_hidden").value = response;
				jquery('#img_preview').attr("src","img/1/"+response);
				jquery('#loading_img').hide();
			}
		}
	});
});

&lt;/script&gt;

&lt;form method="post" name="index" id="index" enctype="multipart/form-data" class="alignleft"&gt;
	&lt;input type="hidden" name="img_name_hidden" id="img_name_hidden" /&gt;
		&lt;table width="100%" border="0" align="center" cellpadding="0" cellspacing="5"&gt;
			&lt;tr&gt;
				&lt;td&gt;&amp;nbsp;&lt;/td&gt;
				&lt;td&gt;
					&lt;span id="imageError" style="font-weight:bold; color:#FF0000;"&gt;&lt;/span&gt;
					&lt;span id="img_preview_delete"&gt; 	&lt;!-- style="display:none" --&gt;
						&lt;img id="img_preview" src="img/no_image.gif"/&gt;	&lt;!-- style="display:none" --&gt;

						&lt;input type="hidden" id="x" name="x" /&gt;
						&lt;input type="hidden" id="y" name="y" /&gt;
						&lt;input type="hidden" id="w" name="w" /&gt;
						&lt;input type="hidden" id="h" name="h" /&gt;
					&lt;/span&gt;
					&lt;span id="img_delete" style="display:none"&gt;
						&lt;a href="javascript:void(0);" onclick="document.getElementById('img_preview_delete').style.display='none'; document.getElementById('img_name_hidden').value = ''; document.getElementById('img_delete').style.display='none';"&gt;
						&lt;?php echo 'Delete'; ?&gt;
						&lt;/a&gt;
					&lt;/span&gt;
				&lt;/td&gt;
				&lt;td&gt;&amp;nbsp;&lt;/td&gt;
			&lt;/tr&gt;

			&lt;tr&gt;
				&lt;td width="135" height="40" align="right" valign="top" class="midtable-toppad"&gt;&lt;?php echo 'Uploade photo : ';?&gt;&lt;/td&gt;
				&lt;td width="254" align="left"&gt;
					&lt;input type="file" name="photo" id="photo"&gt;&amp;nbsp; &lt;img id="loading_img" src="img/loader.gif" style="display:none;z-index:99999;left:100%;top:40%" /&gt;
				&lt;/td&gt;
				&lt;td width="200"&gt;&lt;/td&gt;
			&lt;/tr&gt;
		&lt;/table&gt;
&lt;/form&gt;
&lt;?php
	// This values are used for ajax image upload.
	if((array_key_exists('img_name_hidden', $_REQUEST) &amp;&amp; $_REQUEST['img_name_hidden'] == ''))
	{
		$_SESSION['objImg'] = '';
	}

	//if('Check if image exist in the folder and field is not null in table.')
	if($img == 1)
	{
?&gt;
		&lt;script type="text/javascript" language="javascript"&gt;
		document.getElementById("img_preview_delete").style.display = 'block';
		document.getElementById("img_preview").style.display = 'block';
		document.getElementById("img_delete").style.display = 'block';

		document.getElementById("img_name_hidden").value = '&lt;?php echo 'load image name from table'; ?&gt;';
		document.getElementById('img_preview').src = "&lt;?php echo 'image path with image name'; ?&gt;";

		&lt;/script&gt;
&lt;?php } ?&gt;

<strong>// Save this file as ajax_uploadnew.php</strong>

&lt;?php
session_start();
ajaxuploadimageAction();

function ajaxuploadimageAction()
{
    $userid   = '1';
    $dir_name = 'img/'.$userid;

   		// Create new directory for user. New directory will be created with user id.
    	if (!file_exists($dir_name)) {
			@mkdir($dir_name,0777);
			@chmod($dir_name,0777);
		}
   		uploadfile($dir_name);
   		exit;
}

    function uploadfile($Path)
 	{
    	$userid   = '1';

 		try {

  			if(isset($_FILES["photo"]))
   			{
  				$arrImageData = array();
				$arrImageData = getimagesize($_FILES['photo']['tmp_name']);

				if(($arrImageData[0] &gt; 1000) || ($arrImageData[1] &gt; 1000))
				{
					echo 'size_error';
					exit;
				}
				else {

					if((isset($_SESSION['objImg']))&amp;&amp;($_SESSION['objImg'] != ''))
	  				{
	   					if(file_exists("img/".$userid."/".$_SESSION['objImg'])) {
	   						unlink("img/".$userid."/".$_SESSION['objImg']);
	   					}
	   					$_SESSION['objImg']='';
	  				}

	  				if(!empty($_FILES['photo']['name']))
					{
						$photo_target_path = "img/".$userid."/";
						$photo_name1 = $_FILES['photo']['name'];
						$photo_name = time().$photo_name1;
						$photo_target_path = $photo_target_path .$photo_name; 

						move_uploaded_file($_FILES['photo']['tmp_name'], $photo_target_path);
					}

			        // Write query to update table.

	  				$_SESSION['objImg'] = $photo_name;
	  				echo $photo_name; exit;
				}
   			}
   			else
    			echo "Error occured while file uploading.";

  		} catch (Exception $e) {
  			echo $e-&gt;getMessage();
  			echo "error";
  		}
 	}

?&gt;

// Save this file as ajaxupload.js in js folder
//alert(1);
/**
* Ajax upload
* Project page - http://valums.com/ajax-upload/
* Copyright (c) 2008 Andris Valums, http://valums.com
* Licensed under the MIT license (http://valums.com/mit-license/)
* Version 3.2 (19.05.2009)
*/

/**
* Changes from the previous version:
* 1. Input is cleared after submit is canceled to allow user to select same file
* 2. Fixed problem with FF3 when used on page with smaller font size
*
* For the full changelog please visit:
* http://valums.com/ajax-upload-changelog/
*/

(function(){

var d = document, w = window;

/**
* Get element by id
*/
function get(element){
if (typeof element == "string")
element = d.getElementById(element);
return element;
}

/**
* Attaches event to a dom element
*/
function addEvent(el, type, fn){
if (w.addEventListener){
el.addEventListener(type, fn, false);
} else if (w.attachEvent){
var f = function(){
fn.call(el, w.event);
};
el.attachEvent('on' + type, f)
}
}

/**
* Creates and returns element from html chunk
*/
var toElement = function(){
var div = d.createElement('div');
return function(html){
div.innerHTML = html;
var el = div.childNodes[0];
div.removeChild(el);
return el;
}
}();

function hasClass(ele,cls){
return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}
function addClass(ele,cls) {
if (!hasClass(ele,cls)) ele.className += " "+cls;
}
function removeClass(ele,cls) {
var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
ele.className=ele.className.replace(reg,' ');
}

// getOffset function copied from jQuery lib (http://jquery.com/)
if (document.documentElement["getBoundingClientRect"]){
// Get Offset using getBoundingClientRect
// http://ejohn.org/blog/getboundingclientrect-is-awesome/
var getOffset = function(el){
var box = el.getBoundingClientRect(),
doc = el.ownerDocument,
body = doc.body,
docElem = doc.documentElement,

// for ie
clientTop = docElem.clientTop || body.clientTop || 0,
clientLeft = docElem.clientLeft || body.clientLeft || 0,

// In Internet Explorer 7 getBoundingClientRect property is treated as physical,
// while others are logical. Make all logical, like in IE8.

zoom = 1;
if (body.getBoundingClientRect) {
var bound = body.getBoundingClientRect();
zoom = (bound.right - bound.left)/body.clientWidth;
}
if (zoom &gt; 1){
clientTop = 0;
clientLeft = 0;
}
var top = box.top/zoom + (window.pageYOffset || docElem &amp;&amp; docElem.scrollTop/zoom || body.scrollTop/zoom) - clientTop,
left = box.left/zoom + (window.pageXOffset|| docElem &amp;&amp; docElem.scrollLeft/zoom || body.scrollLeft/zoom) - clientLeft;

return {
top: top,
left: left
};
}

} else {
// Get offset adding all offsets
var getOffset = function(el){
if (w.jQuery){
return jQuery(el).offset();
}

var top = 0, left = 0;
do {
top += el.offsetTop || 0;
left += el.offsetLeft || 0;
}
while (el = el.offsetParent);

return {
left: left,
top: top
};
}
}

function getBox(el){
var left, right, top, bottom;
var offset = getOffset(el);
left = offset.left;
top = offset.top;

right = left + el.offsetWidth;
bottom = top + el.offsetHeight;

return {
left: left,
right: right,
top: top,
bottom: bottom
};
}

/**
* Crossbrowser mouse coordinates
*/
function getMouseCoords(e){
// pageX/Y is not supported in IE
// http://www.quirksmode.org/dom/w3c_cssom.html
if (!e.pageX &amp;&amp; e.clientX){
// In Internet Explorer 7 some properties (mouse coordinates) are treated as physical,
// while others are logical (offset).
var zoom = 1;
var body = document.body;

if (body.getBoundingClientRect) {
var bound = body.getBoundingClientRect();
zoom = (bound.right - bound.left)/body.clientWidth;
}

return {
x: e.clientX / zoom + d.body.scrollLeft + d.documentElement.scrollLeft,
y: e.clientY / zoom + d.body.scrollTop + d.documentElement.scrollTop
};
}

return {
x: e.pageX,
y: e.pageY
};

}
/**
* Function generates unique id
*/
var getUID = function(){
var id = 0;
return function(){
return 'ValumsAjaxUpload' + id++;
}
}();

function fileFromPath(file){
return file.replace(/.*(\/|\\)/, "");
}

function getExt(file){
return (/[.]/.exec(file)) ? /[^.]+$/.exec(file.toLowerCase()) : '';
}

// Please use AjaxUpload , Ajax_upload will be removed in the next version
Ajax_upload = AjaxUpload = function(button, options){
if (button.jquery){
// jquery object was passed
button = button[0];
} else if (typeof button == "string" &amp;&amp; /^#.*/.test(button)){
button = button.slice(1);
}
button = get(button);

this._input = null;
this._button = button;
this._disabled = false;
this._submitting = false;
// Variable changes to true if the button was clicked
// 3 seconds ago (requred to fix Safari on Mac error)
this._justClicked = false;
this._parentDialog = d.body;

if (window.jQuery &amp;&amp; jQuery.ui &amp;&amp; jQuery.ui.dialog){
var parentDialog = jQuery(self._button).parents('.ui-dialog-content');
if (parentDialog.length){
this._parentDialog = parentDialog[0];
}
}

this._settings = {
// Location of the server-side upload script
action: 'upload.php',
// File upload name
name: 'userfile',
// Additional data to send
data: {},
// Submit file as soon as it's selected
autoSubmit: true,
// The type of data that you're expecting back from the server.
// Html and xml are detected automatically.
// Only useful when you are using json data as a response.
// Set to "json" in that case.
responseType: false,
// When user selects a file, useful with autoSubmit disabled
onChange: function(file, extension){},
// Callback to fire before file is uploaded
// You can return false to cancel upload
onSubmit: function(file, extension){},
// Fired when file upload is completed
// WARNING! DO NOT USE "FALSE" STRING AS A RESPONSE!
onComplete: function(file, response) {}
};

// Merge the users options with our defaults
for (var i in options) {
this._settings[i] = options[i];
}

this._createInput();
this._rerouteClicks();
}

// assigning methods to our class
AjaxUpload.prototype = {
setData : function(data){
this._settings.data = data;
},
disable : function(){
this._disabled = true;
},
enable : function(){
this._disabled = false;
},
// removes ajaxupload
destroy : function(){
if(this._input){
if(this._input.parentNode){
this._input.parentNode.removeChild(this._input);
}
this._input = null;
}
},
/**
* Creates invisible file input above the button
*/
_createInput : function(){
var self = this;
var input = d.createElement("input");
input.setAttribute('type', 'file');
input.setAttribute('name', this._settings.name);
var styles = {
'position' : 'absolute'
,'margin': '-5px 0 0 -175px'
,'padding': 0
,'width': '220px'
,'height': '30px'
,'fontSize': '14px'
,'opacity': 0
,'cursor': 'pointer'
,'display' : 'none'
,'zIndex' : 2147483583 //Max zIndex supported by Opera 9.0-9.2x
// Strange, I expected 2147483647
};
for (var i in styles){
input.style[i] = styles[i];
}

// Make sure that element opacity exists
// (IE uses filter instead)
if ( ! (input.style.opacity === "0")){
input.style.filter = "alpha(opacity=0)";
}

this._parentDialog.appendChild(input);

addEvent(input, 'change', function(){
// get filename from input
var file = fileFromPath(this.value);
if(self._settings.onChange.call(self, file, getExt(file)) == false ){
return;
}
// Submit form when value is changed
if (self._settings.autoSubmit){
self.submit();
}
});

// Fixing problem with Safari
// The problem is that if you leave input before the file select dialog opens
// it does not upload the file.
// As dialog opens slowly (it is a sheet dialog which takes some time to open)
// there is some time while you can leave the button.
// So we should not change display to none immediately
addEvent(input, 'click', function(){
self.justClicked = true;
setTimeout(function(){
// we will wait 3 seconds for dialog to open
self.justClicked = false;
}, 3000);
});

this._input = input;
},
_rerouteClicks : function (){
var self = this;

// IE displays 'access denied' error when using this method
// other browsers just ignore click()
// addEvent(this._button, 'click', function(e){
// self._input.click();
// });

var box, dialogOffset = {top:0, left:0}, over = false;
addEvent(self._button, 'mouseover', function(e){
if (!self._input || over) return;
over = true;
box = getBox(self._button);

if (self._parentDialog != d.body){
dialogOffset = getOffset(self._parentDialog);
}
});

// we can't use mouseout on the button,
// because invisible input is over it
addEvent(document, 'mousemove', function(e){
var input = self._input;
if (!input || !over) return;

if (self._disabled){
removeClass(self._button, 'hover');
input.style.display = 'none';
return;
}

var c = getMouseCoords(e);

if ((c.x &gt;= box.left) &amp;&amp; (c.x &lt;= box.right) &amp;&amp;
(c.y &gt;= box.top) &amp;&amp; (c.y &lt;= box.bottom)){
input.style.top = c.y - dialogOffset.top + 'px';
input.style.left = c.x - dialogOffset.left + 'px';
input.style.display = 'block';
addClass(self._button, 'hover');
} else {
// mouse left the button
over = false;
if (!self.justClicked){
input.style.display = 'none';
}
removeClass(self._button, 'hover');
}
});

},
/**
* Creates iframe with unique name
*/
_createIframe : function(){
// unique name
// We cannot use getTime, because it sometimes return
// same value in safari :(
var id = getUID();

// Remove ie6 "This page contains both secure and nonsecure items" prompt
// http://tinyurl.com/77w9wh
var iframe = toElement('&lt;iframe src="javascript:false;" name="' + id + '" /&gt;');
iframe.id = id;
iframe.style.display = 'none';
d.body.appendChild(iframe);
return iframe;
},
/**
* Upload file without refreshing the page
*/
submit : function(){
var self = this, settings = this._settings;

if (this._input.value === ''){
// there is no file
return;
}

// get filename from input
var file = fileFromPath(this._input.value);

// execute user event
if (! (settings.onSubmit.call(this, file, getExt(file)) == false)) {
// Create new iframe for this submission
var iframe = this._createIframe();

// Do not submit if user function returns false
var form = this._createForm(iframe);
form.appendChild(this._input);

form.submit();

d.body.removeChild(form);
form = null;
this._input = null;

// create new input
this._createInput();

var toDeleteFlag = false;

addEvent(iframe, 'load', function(e){
if (iframe.src == "about:blank"){
// First time around, do not delete.
if( toDeleteFlag ){
// Fix busy state in FF3
setTimeout( function() {
d.body.removeChild(iframe);
}, 0);
}
return;
}

var doc = iframe.contentDocument ? iframe.contentDocument : frames[iframe.id].document;

// fixing Opera 9.26
if (doc.readyState &amp;&amp; doc.readyState != 'complete'){
// Opera fires load event multiple times
// Even when the DOM is not ready yet
// this fix should not affect other browsers
return;
}

// fixing Opera 9.64
if (doc.body &amp;&amp; doc.body.innerHTML == "false"){
// In Opera 9.64 event was fired second time
// when body.innerHTML changed from false
// to server response approx. after 1 sec
return;
}

var response;

if (doc.XMLDocument){
// response is a xml document IE property
response = doc.XMLDocument;
} else if (doc.body){
// response is html document or plain text
response = doc.body.innerHTML;
if (settings.responseType == 'json'){
response = window["eval"]("(" + response + ")");
}
} else {
// response is a xml document
var response = doc;
}

settings.onComplete.call(self, file, response);

// Reload blank page, so that reloading main page
// does not re-submit the post. Also, remember to
// delete the frame
toDeleteFlag = true;
iframe.src = "about:blank"; //load event fired
});

} else {
// clear input to allow user to select same file
// Doesn't work in IE6
// this._input.value = '';
d.body.removeChild(this._input);
this._input = null;

// create new input
this._createInput();
}
},
/**
* Creates form, that will be submitted to iframe
*/
_createForm : function(iframe){
var settings = this._settings;

// method, enctype must be specified here
// because changing this attr on the fly is not allowed in IE 6/7
var form = toElement('&lt;form method="post" enctype="multipart/form-data"&gt;&lt;/form&gt;');
form.style.display = 'none';
form.action = settings.action;
form.target = iframe.name;
d.body.appendChild(form);

// Create hidden input element for each data key
for (var prop in settings.data){
var el = d.createElement("input");
el.type = 'hidden';
el.name = prop;
el.value = settings.data[prop];
form.appendChild(el);
}
return form;
}
};
})();// Create img folder to save the image. Save loader.gif and no_image.gif in the img folder
<a href="http://odedranilesh.files.wordpress.com/2011/09/no_image.gif"><img class="alignnone size-full wp-image-131" title="no_image" src="http://odedranilesh.files.wordpress.com/2011/09/no_image.gif?w=450" alt=""   /></a>

<a href="http://odedranilesh.files.wordpress.com/2011/09/loader.gif"><img class="alignnone size-full wp-image-130" title="loader" src="http://odedranilesh.files.wordpress.com/2011/09/loader.gif?w=450" alt=""   /></a></pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/odedranilesh.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/odedranilesh.wordpress.com/128/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/odedranilesh.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/odedranilesh.wordpress.com/128/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/odedranilesh.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/odedranilesh.wordpress.com/128/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/odedranilesh.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/odedranilesh.wordpress.com/128/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/odedranilesh.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/odedranilesh.wordpress.com/128/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/odedranilesh.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/odedranilesh.wordpress.com/128/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/odedranilesh.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/odedranilesh.wordpress.com/128/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=odedranilesh.wordpress.com&amp;blog=7292930&amp;post=128&amp;subd=odedranilesh&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://odedranilesh.wordpress.com/2011/09/03/ajax-image-uploading/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/501803e3b68d6d613b93b6f305f877ab?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">odedranilesh</media:title>
		</media:content>

		<media:content url="http://odedranilesh.files.wordpress.com/2011/09/no_image.gif" medium="image">
			<media:title type="html">no_image</media:title>
		</media:content>

		<media:content url="http://odedranilesh.files.wordpress.com/2011/09/loader.gif" medium="image">
			<media:title type="html">loader</media:title>
		</media:content>
	</item>
		<item>
		<title>Image Cropping</title>
		<link>http://odedranilesh.wordpress.com/2011/09/03/image-cropping/</link>
		<comments>http://odedranilesh.wordpress.com/2011/09/03/image-cropping/#comments</comments>
		<pubDate>Sat, 03 Sep 2011 05:42:33 +0000</pubDate>
		<dc:creator>Nilesh Odedra</dc:creator>
				<category><![CDATA[Image Manipulation]]></category>
		<category><![CDATA[crop image]]></category>
		<category><![CDATA[cropping image]]></category>
		<category><![CDATA[gif image cropping]]></category>
		<category><![CDATA[image cropping]]></category>
		<category><![CDATA[jpg image cropping]]></category>
		<category><![CDATA[js image crop]]></category>
		<category><![CDATA[php image crop]]></category>
		<category><![CDATA[png image cropping]]></category>

		<guid isPermaLink="false">http://odedranilesh.wordpress.com/?p=114</guid>
		<description><![CDATA[// Save this as index.php &#60;?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { $targ_w = 116; $targ_h = 131; $jpeg_quality = 90; // Create JPG thumbnail image. /* $src = 'flowers.jpg'; $img_r = imagecreatefromjpeg($src); $dst_r = ImageCreateTrueColor( $targ_w, $targ_h ); imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'], $targ_w,$targ_h,$_POST['w'],$_POST['h']); imagejpeg($dst_r,'path to save your image\f.jpg',$jpeg_quality);*/ // Create GIF thumbnail image. /* $src = 'teens.gif'; $img_r [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=odedranilesh.wordpress.com&amp;blog=7292930&amp;post=114&amp;subd=odedranilesh&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<pre>// Save this as index.php
&lt;?php
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
	$targ_w = 116;
	$targ_h = 131;
	$jpeg_quality = 90;

	// Create JPG thumbnail image.
	/*
	$src = 'flowers.jpg';
	$img_r = imagecreatefromjpeg($src);
	$dst_r = ImageCreateTrueColor( $targ_w, $targ_h );

	imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],
	$targ_w,$targ_h,$_POST['w'],$_POST['h']);

	imagejpeg($dst_r,'path to save your image\f.jpg',$jpeg_quality);*/

	// Create GIF thumbnail image.
	/*
	$src = 'teens.gif';
	$img_r = imagecreatefromgif($src);
	$dst_r = ImageCreateTrueColor( $targ_w, $targ_h );

	imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],
	$targ_w,$targ_h,$_POST['w'],$_POST['h']);

	imagegif($dst_r, 'path to save your image\t.gif', $jpeg_quality);*/	

	// Create PNG thumbnail image.

	$src = 'bunny.png';
	$img_r = imagecreatefrompng($src);
	$dst_r = ImageCreateTrueColor( $targ_w, $targ_h );

	imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],
	$targ_w,$targ_h,$_POST['w'],$_POST['h']);

	// For creating png thumbnail image we will not use image quality.
	imagepng($dst_r, 'path to save your image\b.png');
	exit;
}
// If not a POST request, display page below:
?&gt;
&lt;html&gt;
	&lt;head&gt;
		&lt;script src="js/jquery.min.js"&gt;&lt;/script&gt;
		&lt;script src="js/jquery.Jcrop.js"&gt;&lt;/script&gt;
		&lt;link rel="stylesheet" href="css/jquery.Jcrop.css" type="text/css" /&gt;

		&lt;script language="Javascript"&gt;

			$(function(){

				$('#img_preview').Jcrop({
					aspectRatio: 116/131,
					onSelect: updateCoords
				});

			});

			function updateCoords(c)
			{
				$('#x').val(c.x);
				$('#y').val(c.y);
				$('#w').val(c.w);
				$('#h').val(c.h);
			};

			function checkCoords()
			{
				if (parseInt($('#w').val())) return true;
				alert('Please select a crop region then press submit.');
				return false;
			};

		&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
	&lt;div id="outer"&gt;
	&lt;div class="jcExample"&gt;
	&lt;div class="article"&gt;
		&lt;h1&gt;Jcrop - Crop Behavior&lt;/h1&gt;

		&lt;!-- This is the image we're attaching Jcrop to --&gt;
		&lt;!--&lt;img src="flowers.jpg" id="img_preview" /&gt;
		&lt;img src="teens.gif" id="img_preview" /&gt;--&gt;
		&lt;img src="bunny.png" id="img_preview" /&gt;

		&lt;!-- This is the form that our event handler fills --&gt;
		&lt;form action="index.php" method="post" onsubmit="return checkCoords();"&gt;
			&lt;input type="hidden" id="x" name="x" /&gt;
			&lt;input type="hidden" id="y" name="y" /&gt;
			&lt;input type="hidden" id="w" name="w" /&gt;
			&lt;input type="hidden" id="h" name="h" /&gt;
			&lt;input type="submit" value="Crop Image" /&gt;
		&lt;/form&gt;

		&lt;p&gt;
			&lt;b&gt;An example server-side crop script.&lt;/b&gt; Hidden form values
			are set when a selection is made. If you press the &lt;i&gt;Crop Image&lt;/i&gt;
			button, the form will be submitted and a 116x131 thumbnail will be
			dumped to the browser. Try it!
		&lt;/p&gt;
	&lt;/div&gt;
	&lt;/div&gt;
	&lt;/div&gt;
	&lt;/body&gt;
&lt;/html&gt;

// Save below css as jquery.Jcrop.css in css folder.
/* Fixes issue here http://code.google.com/p/jcrop/issues/detail?id=1 */
.jcrop-holder { text-align: left; }

.jcrop-vline, .jcrop-hline
{
	font-size: 0px;
	position: absolute;
	background: white url('Jcrop.gif') top left repeat;
}
.jcrop-vline { height: 100%; width: 1px !important; }
.jcrop-hline { width: 100%; height: 1px !important; }
.jcrop-vline.right { right: 0px; }
.jcrop-hline.bottom { bottom: 0px; }
.jcrop-handle {
	font-size: 1px;
	width: 7px !important;
	height: 7px !important;
	border: 1px #eee solid;
	background-color: #333;
}

.jcrop-tracker { width: 100%; height: 100%; }

.custom .jcrop-vline,
.custom .jcrop-hline
{
	background: yellow;
}
.custom .jcrop-handle
{
	border-color: black;
	background-color: #C7BB00;
	-moz-border-radius: 3px;
	-webkit-border-radius: 3px;
}
// Download two jquery.Jcrop.js (Version v0.9.9) and jquery.min.js (Version 1.5.1) and save it in js folder.
// Save this image in css folder.
<a href="http://odedranilesh.files.wordpress.com/2011/09/jcrop1.gif"><img class="alignnone size-full wp-image-118" title="Jcrop" src="http://odedranilesh.files.wordpress.com/2011/09/jcrop1.gif?w=450" alt=""   /></a></pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/odedranilesh.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/odedranilesh.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/odedranilesh.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/odedranilesh.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/odedranilesh.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/odedranilesh.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/odedranilesh.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/odedranilesh.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/odedranilesh.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/odedranilesh.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/odedranilesh.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/odedranilesh.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/odedranilesh.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/odedranilesh.wordpress.com/114/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=odedranilesh.wordpress.com&amp;blog=7292930&amp;post=114&amp;subd=odedranilesh&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://odedranilesh.wordpress.com/2011/09/03/image-cropping/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/501803e3b68d6d613b93b6f305f877ab?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">odedranilesh</media:title>
		</media:content>

		<media:content url="http://odedranilesh.files.wordpress.com/2011/09/jcrop1.gif" medium="image">
			<media:title type="html">Jcrop</media:title>
		</media:content>
	</item>
		<item>
		<title>Create, Read and Delete JS Cookie</title>
		<link>http://odedranilesh.wordpress.com/2011/09/02/create-read-and-delete-js-cookie/</link>
		<comments>http://odedranilesh.wordpress.com/2011/09/02/create-read-and-delete-js-cookie/#comments</comments>
		<pubDate>Fri, 02 Sep 2011 12:02:05 +0000</pubDate>
		<dc:creator>Nilesh Odedra</dc:creator>
				<category><![CDATA[JS Operation]]></category>
		<category><![CDATA[cookie read]]></category>
		<category><![CDATA[cookies]]></category>
		<category><![CDATA[delete cookie]]></category>
		<category><![CDATA[js cookie]]></category>
		<category><![CDATA[JS cookies]]></category>
		<category><![CDATA[read cookie]]></category>
		<category><![CDATA[write cookie]]></category>

		<guid isPermaLink="false">http://odedranilesh.wordpress.com/?p=103</guid>
		<description><![CDATA[function createCookie(name,value,days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = &#8220;; expires=&#8221;+date.toGMTString(); } else var expires = &#8220;&#8221;; document.cookie = name+&#8221;=&#8221;+value+expires+&#8221;; path=/&#8221;; } function readCookie(name) { var nameEQ = name + &#8220;=&#8221;; var ca = document.cookie.split(&#8216;;&#8217;); for(var i=0;i &#60; ca.length;i++) { var c = ca[i]; while (c.charAt(0)==&#8217; &#8216;) c = [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=odedranilesh.wordpress.com&amp;blog=7292930&amp;post=103&amp;subd=odedranilesh&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>function createCookie(name,value,days) {<br />
if (days) {<br />
var date = new Date();<br />
date.setTime(date.getTime()+(days*24*60*60*1000));<br />
var expires = &#8220;; expires=&#8221;+date.toGMTString();<br />
}<br />
else var expires = &#8220;&#8221;;<br />
document.cookie = name+&#8221;=&#8221;+value+expires+&#8221;; path=/&#8221;;<br />
}</p>
<p>function readCookie(name) {<br />
var nameEQ = name + &#8220;=&#8221;;<br />
var ca = document.cookie.split(&#8216;;&#8217;);<br />
for(var i=0;i &lt; ca.length;i++) {<br />
var c = ca[i];<br />
while (c.charAt(0)==&#8217; &#8216;) c = c.substring(1,c.length);<br />
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);<br />
}<br />
return null;<br />
}</p>
<p>function eraseCookie(name) {<br />
createCookie(name,&#8221;",-1);<br />
}</p>
<p>// Creating a cookie<br />
createCookie(&#8216;cookiename&#8217;,'value&#8217;,'int-no of days&#8217;);</p>
<p>// Read cookie<br />
readCookie(&#8216;cookiename&#8217;)</p>
<p>// Erase cookie<br />
eraseCookie(&#8216;cookiename&#8217;);</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/odedranilesh.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/odedranilesh.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/odedranilesh.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/odedranilesh.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/odedranilesh.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/odedranilesh.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/odedranilesh.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/odedranilesh.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/odedranilesh.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/odedranilesh.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/odedranilesh.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/odedranilesh.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/odedranilesh.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/odedranilesh.wordpress.com/103/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=odedranilesh.wordpress.com&amp;blog=7292930&amp;post=103&amp;subd=odedranilesh&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://odedranilesh.wordpress.com/2011/09/02/create-read-and-delete-js-cookie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/501803e3b68d6d613b93b6f305f877ab?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">odedranilesh</media:title>
		</media:content>
	</item>
		<item>
		<title>Zend Interview Questions</title>
		<link>http://odedranilesh.wordpress.com/2011/07/29/zend-interview-questions/</link>
		<comments>http://odedranilesh.wordpress.com/2011/07/29/zend-interview-questions/#comments</comments>
		<pubDate>Fri, 29 Jul 2011 11:07:58 +0000</pubDate>
		<dc:creator>Nilesh Odedra</dc:creator>
				<category><![CDATA[Interview Questions]]></category>
		<category><![CDATA[zend framework question]]></category>
		<category><![CDATA[zend framework question answer]]></category>
		<category><![CDATA[zend interview answer]]></category>
		<category><![CDATA[Zend interview question]]></category>
		<category><![CDATA[zend question - answer]]></category>

		<guid isPermaLink="false">http://odedranilesh.wordpress.com/?p=96</guid>
		<description><![CDATA[1) Is ZF a component library or a framework? ZF is both. Zend Framework provides all the components required for most web applications in a single distribution. But Zend Framework components are also loosely coupled, making it easy to use just a few components in a web application- even alongside other frameworks! Using this use-at-will [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=odedranilesh.wordpress.com&amp;blog=7292930&amp;post=96&amp;subd=odedranilesh&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>1) Is ZF a component library or a framework?</p>
<p>ZF is both. Zend Framework provides all the components required for most web applications in a single distribution. But Zend Framework components are also loosely coupled, making it easy to use just a few components in a web application- even alongside other frameworks! Using this use-at-will architecture, we are implementing features commonly found in more monolithic frameworks. In fact, we are currently working on a tooling component for the 1.8 release that will make it simpler to build applications using ZF components, yet will not sacrifice the use-at-will nature of existing ZF components. It&#8217;s a testament to the use-at-will architecture of Zend Framework that the tooling component itself can be used standalone.</p>
<p>2) What is autoloader?<br />
	Autoloader is function that load all the object on start up.</p>
<p>3) What is use of Zend front controller?<br />
	Routing and dispatching is managed in the front controller. It collects all the request from the server and handles it.</p>
<p>4) What is the use of Bootstrap?<br />
	Apart from index if we want to do any extra configuration regarding database and other things that is done within bootstrap.</p>
<p>5) Zend auth<br />
	It is used to authenticate user, for example like admin, general etc.</p>
<p>6) Zend Acl<br />
	Based on the zend authentication it allows the user to access certain actions.</p>
<p>7) How do u set Module name, Controller name, and Action name in Zend framework?<br />
	a) $request-&gt;setModuleName(&#8216;front&#8217;);<br />
	b) $request-&gt;setControllerName(&#8216;address&#8217;);<br />
	c) $request-&gt;setActionName(&#8216;addresslist&#8217;);</p>
<p>8) Configuration in Zend Framework, application.ini file?<br />
	Configuration can be done in application.ini file in Zend framework.  This file in the path application/configs/application.ini. </p>
<p>9) Checking whether form posted or not in Zend framework?<br />
	$request = $this-&gt;getRequest();<br />
	$_GET = $request-&gt;getParams();<br />
	$_POST = $request-&gt;getPost();</p>
<p>10) Does Zend Framework support PHP 4?<br />
	No. Zend Framework was built to use all of the sophisticated object oriented features of PHP 5 and take advantage of significant performance and security enhancements.</p>
<p>11) Fetch last inserted id, fetch all record and fetch a single record.<br />
	$this-&gt;_db-&gt;lastInsertId();<br />
	$this-&gt;_db-&gt;fetchAll($sql);<br />
	$this-&gt;_db-&gt;fetchRow($sql);</p>
<p>12) Difference between Zend_Registry and Zend_Session?<br />
	The basic difference between these objects is the ‘scope’ in which they are valid:<br />
		a) Zend_Registry : request scope<br />
		b) Zend_Session : session scope</p>
<p>	Zend_Registry is used to store objects/values for the current request. In short, anything that you commit to Registry in index.php can be accessed from other controllers/actions (because EVERY request is first routed to the index.php   bootstrapper via the .htaccess file). Config parameters and db parameters are generally prepped for global use using the Zend_Registry object.</p>
<p>	Zend_Session actually uses PHP sessions. Data stored using Zend_Session can be accessed in different/all pages. So, if you want to create a variable named ‘UserRole’ in the /auth/login script and want it to be accessible in /auth/redirect, you would use Zend_Session. </p>
<p>13) When do we need to disable layout?<br />
	At the time of calling AJAX to fetch we need to disable layout.<br />
		$this-&gt;_helper-&gt;layout()-&gt;disableLayout();<br />
		$this-&gt;_helper-&gt;viewRenderer-&gt;setNoRender(true);</p>
<p>14) Filters in Zend Framework with Examples?<br />
	The Zend_Filter component provides a set of commonly needed data filters. It also provides a simple filter chaining mechanism by which multiple filters may be applied to a single datum in a user-defined order.</p>
<p>	Example:<br />
		// Add an email element<br />
		$this-&gt;addElement(&#8216;text&#8217;, &#8216;email&#8217;, array(<br />
			&#8216;label&#8217;      =&gt; &#8216;Your email address:&#8217;,<br />
			&#8216;required&#8217;   =&gt; true,<br />
			&#8216;filters&#8217;    =&gt; array(&#8216;StringTrim&#8217;),<br />
			&#8216;validators&#8217; =&gt; array(<br />
				&#8216;EmailAddress&#8217;,<br />
			)<br />
		));<br />
	Other Filters:</p>
<p>	Alnum &#8211; Zend_Filter_Alnum is a filter which returns only alphabetic characters and digits. All other characters are supressed.<br />
	Alpha &#8211; Zend_Filter_Alpha is a filter which returns the string $value, removing all but alphabetic characters. This filter includes an option to also allow white space characters.</p>
<p>15) Name some Important component in zend framework?<br />
	Uses of Zend_Controller<br />
		Gives the request &amp; reponse methods by using its sub-classes.<br />
			$request = new Zend_Controller_Request_Http()<br />
			$response = new Zend_Controller_Response_Http()</p>
<p>	Uses of Zend_Date<br />
		Date related processing can be done using this component.</p>
<p>	Uses of Zend_File_Transfer<br />
		it provides extensive support for file uploads and downloads.</p>
<p>	Uses of Zend_Db<br />
		It is used to doing database related purpose in our appication.</p>
<p>	Uses of Zend_Paginator<br />
		Doing the pagination in our application.</p>
<p>	Uses of Zend_Auth<br />
		It is used to authenticate a user.</p>
<p>		$auth = Zend_Auth::getInstance();<br />
		$results = $auth-&gt;authenticate($adapter);<br />
		if ($results-&gt;isValid()){<br />
			/* user successfully authenticate into login process */<br />
		}</p>
<p>	Zend_Session_Namespace<br />
		This is a simple proxy class to use API into the Zend_Session managed $_SESSION Superglobal.</p>
<p>16) Where is the model in ZF&#8217;s MVC implementation?<br />
	The model component can vary dramatically in responsibilities and data store from one MVC application to the next.</p>
<p>17) How to call two different views from same action?<br />
	Example1:<br />
		Public function indexAction() {<br />
			If(condition)<br />
				$this-&gt;render(‘yourview.phtml’);<br />
			Else<br />
				Index.phtml;</p>
<p>	Example2:<br />
		Public function indexAction() {<br />
		}<br />
		Now in your index.phtml you can have this statement to call other view<br />
		$this-&gt;action(&#8216;action name’,&#8217;controller name’,&#8217;module name’,array(&#8216;parameter name&#8217;=&gt;’parameter value’));</p>
<p>18) Can we call a model in view?<br />
	Yes, you can call a model in view. Simple create the object and call the method.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/odedranilesh.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/odedranilesh.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/odedranilesh.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/odedranilesh.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/odedranilesh.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/odedranilesh.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/odedranilesh.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/odedranilesh.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/odedranilesh.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/odedranilesh.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/odedranilesh.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/odedranilesh.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/odedranilesh.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/odedranilesh.wordpress.com/96/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=odedranilesh.wordpress.com&amp;blog=7292930&amp;post=96&amp;subd=odedranilesh&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://odedranilesh.wordpress.com/2011/07/29/zend-interview-questions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/501803e3b68d6d613b93b6f305f877ab?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">odedranilesh</media:title>
		</media:content>
	</item>
		<item>
		<title>Generate Random Password</title>
		<link>http://odedranilesh.wordpress.com/2011/07/13/generate-random-password/</link>
		<comments>http://odedranilesh.wordpress.com/2011/07/13/generate-random-password/#comments</comments>
		<pubDate>Wed, 13 Jul 2011 12:56:54 +0000</pubDate>
		<dc:creator>Nilesh Odedra</dc:creator>
				<category><![CDATA[php tutor]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[random password]]></category>
		<category><![CDATA[random string]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[unique password]]></category>
		<category><![CDATA[unique random password]]></category>
		<category><![CDATA[unique random string]]></category>
		<category><![CDATA[unique string]]></category>

		<guid isPermaLink="false">http://odedranilesh.wordpress.com/?p=85</guid>
		<description><![CDATA[This function is used to generate random string/password. You can generate string with small letter, capital letter, digit and special characters. &#60;?php function genRandomPass($pw_length = 8, $use_caps = true, $use_numeric = true, $use_specials = true, $use_small = true) { $chars = array(); $pw = array(); $caps = array(); $numbers = array(); $all = array(); $num_specials [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=odedranilesh.wordpress.com&amp;blog=7292930&amp;post=85&amp;subd=odedranilesh&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This function is used to generate random string/password. You can generate string with small letter, capital letter, digit and special characters.</p>
<p>&lt;?php<br />
function genRandomPass($pw_length = 8, $use_caps = true, $use_numeric = true, $use_specials = true, $use_small = true) {<br />
$chars = array();<br />
$pw = array();<br />
$caps = array();<br />
$numbers = array();<br />
$all = array();<br />
$num_specials = $pw_length;<br />
$reg_length = $pw_length;<br />
$pws = array();</p>
<p>if ($use_small) for ($ch = 97; $ch &lt;= 122; $ch++) $chars[] = $ch; // create a-z<br />
if ($use_caps) for ($ca = 65; $ca &lt;= 90; $ca++) $caps[] = $ca; // create A-Z<br />
if ($use_numeric) {<br />
for ($nu = 48; $nu &lt;= 57; $nu++) $numbers[] = $nu; // create 0-9<br />
if($use_small == false || $use_caps == false || $use_numeric == false) {<br />
for ($nu = 48; $nu &lt;= 57; $nu++) $numbers[] = $nu; // create 0-9<br />
}<br />
}</p>
<p>$all = array_merge($chars, $caps, $numbers);<br />
if ($use_specials) {<br />
if($use_small == true || $use_caps == true || $use_numeric == true) {<br />
$reg_length = ceil($pw_length*0.75);<br />
$num_specials = $pw_length &#8211; $reg_length;<br />
if ($num_specials &gt; 5) $num_specials = 5;<br />
}<br />
for ($si = 33; $si &lt;= 47; $si++) $signs[] = $si;<br />
$rs_keys = array_rand($signs, $num_specials);<br />
foreach ($rs_keys as $rs) {<br />
$pws[] = chr($signs[$rs]);<br />
}<br />
}</p>
<p>if(sizeof($all) &gt; 0) {<br />
$rand_keys = array_rand($all, $reg_length);<br />
foreach ($rand_keys as $rand) {<br />
$pw[] = chr($all[$rand]);<br />
}<br />
}</p>
<p>$compl = array_merge($pw, $pws);<br />
shuffle($compl);<br />
return implode(&#8221;, $compl);<br />
}</p>
<p>//Generate string/password with 10 character only small letters.<br />
echo genRandomPass(10, false, false, false, true);<br />
//Generate string/password with 12 character small letters, digit, special characters.<br />
echo genRandomPass(10, false, true, true, true);<br />
?&gt;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/odedranilesh.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/odedranilesh.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/odedranilesh.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/odedranilesh.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/odedranilesh.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/odedranilesh.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/odedranilesh.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/odedranilesh.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/odedranilesh.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/odedranilesh.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/odedranilesh.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/odedranilesh.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/odedranilesh.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/odedranilesh.wordpress.com/85/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=odedranilesh.wordpress.com&amp;blog=7292930&amp;post=85&amp;subd=odedranilesh&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://odedranilesh.wordpress.com/2011/07/13/generate-random-password/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/501803e3b68d6d613b93b6f305f877ab?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">odedranilesh</media:title>
		</media:content>
	</item>
		<item>
		<title>Shorten a text</title>
		<link>http://odedranilesh.wordpress.com/2009/11/05/shorten-a-text/</link>
		<comments>http://odedranilesh.wordpress.com/2009/11/05/shorten-a-text/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 08:54:06 +0000</pubDate>
		<dc:creator>Nilesh Odedra</dc:creator>
				<category><![CDATA[php tutor]]></category>
		<category><![CDATA[display short text]]></category>
		<category><![CDATA[shorten a text]]></category>

		<guid isPermaLink="false">http://odedranilesh.wordpress.com/?p=81</guid>
		<description><![CDATA[&#60;?php echo $txt = &#8220;India has most historical places.&#8221;; echo &#8220;&#60;br&#62;&#8221;; echo ShortenTxt($txt);  function ShortenTxt($txt) {  // Change to the number of characters to display         $chars = 20;  $txt = $txt.&#8221; &#8220;;  $txt = substr($txt,0,$chars);   $txt = substr($txt,0,strrpos($txt,&#8217; &#8216;));  $txt = $txt.&#8221;&#8230;&#8221;;         return $txt; } ?&#62;<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=odedranilesh.wordpress.com&amp;blog=7292930&amp;post=81&amp;subd=odedranilesh&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>&lt;?php</p>
<p>echo $txt = &#8220;India has most historical places.&#8221;;<br />
echo &#8220;&lt;br&gt;&#8221;;<br />
echo ShortenTxt($txt); </p>
<p>function ShortenTxt($txt)<br />
{<br />
 // Change to the number of characters to display       <br />
 $chars = 20;<br />
 $txt = $txt.&#8221; &#8220;;<br />
 $txt = substr($txt,0,$chars); <br />
 $txt = substr($txt,0,strrpos($txt,&#8217; &#8216;));<br />
 $txt = $txt.&#8221;&#8230;&#8221;;       <br />
 return $txt;<br />
}<br />
?&gt;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/odedranilesh.wordpress.com/81/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/odedranilesh.wordpress.com/81/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/odedranilesh.wordpress.com/81/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/odedranilesh.wordpress.com/81/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/odedranilesh.wordpress.com/81/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/odedranilesh.wordpress.com/81/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/odedranilesh.wordpress.com/81/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/odedranilesh.wordpress.com/81/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/odedranilesh.wordpress.com/81/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/odedranilesh.wordpress.com/81/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/odedranilesh.wordpress.com/81/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/odedranilesh.wordpress.com/81/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/odedranilesh.wordpress.com/81/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/odedranilesh.wordpress.com/81/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=odedranilesh.wordpress.com&amp;blog=7292930&amp;post=81&amp;subd=odedranilesh&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://odedranilesh.wordpress.com/2009/11/05/shorten-a-text/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/501803e3b68d6d613b93b6f305f877ab?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">odedranilesh</media:title>
		</media:content>
	</item>
		<item>
		<title>Javascript Lightbox Image</title>
		<link>http://odedranilesh.wordpress.com/2009/11/02/javascript-lightbox-image/</link>
		<comments>http://odedranilesh.wordpress.com/2009/11/02/javascript-lightbox-image/#comments</comments>
		<pubDate>Mon, 02 Nov 2009 06:24:10 +0000</pubDate>
		<dc:creator>Nilesh Odedra</dc:creator>
				<category><![CDATA[JS Operation]]></category>
		<category><![CDATA[image gallary]]></category>
		<category><![CDATA[Lightbox image]]></category>

		<guid isPermaLink="false">http://odedranilesh.wordpress.com/?p=77</guid>
		<description><![CDATA[Add this script in the head section. &#60;script language=&#8221;javascript&#8221; type=&#8221;text/javascript&#8221;&#62; function showPic(whichpic) { if (document.getElementById) { //  alert(document.getElementById); document.getElementById(&#8216;placeholder&#8217;).src = whichpic.href; return false; if (whichpic.title) { document.getElementById(&#8216;desc&#8217;).childNodes[0].nodeValue = whichpic.title; } else { document.getElementById(&#8216;desc&#8217;).childNodes[0].nodeValue = whichpic.childNodes[0].nodeValue; } return false; } else { return true; } } var previousToggle=null; function toggleMe(a){ var e=document.getElementById(a); if(!e)return true; if(e.style.display==&#8221;none&#8221;){ e.style.display=&#8221;block&#8221;; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=odedranilesh.wordpress.com&amp;blog=7292930&amp;post=77&amp;subd=odedranilesh&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Add this script in the head section.</strong></p>
<p>&lt;script language=&#8221;javascript&#8221; type=&#8221;text/javascript&#8221;&gt;<br />
function showPic(whichpic) {</p>
<p>if (document.getElementById) {<br />
//  alert(document.getElementById);</p>
<p>document.getElementById(&#8216;placeholder&#8217;).src = whichpic.href;<br />
return false;<br />
if (whichpic.title) {<br />
document.getElementById(&#8216;desc&#8217;).childNodes[0].nodeValue = whichpic.title;<br />
} else {<br />
document.getElementById(&#8216;desc&#8217;).childNodes[0].nodeValue = whichpic.childNodes[0].nodeValue;<br />
}<br />
return false;<br />
} else {<br />
return true;<br />
}<br />
}</p>
<p>var previousToggle=null;<br />
function toggleMe(a){<br />
var e=document.getElementById(a);<br />
if(!e)return true;<br />
if(e.style.display==&#8221;none&#8221;){<br />
e.style.display=&#8221;block&#8221;;<br />
if(previousToggle)previousToggle.style.display=&#8221;none&#8221;;<br />
previousToggle=e;<br />
}<br />
return true;<br />
}</p>
<p>&lt;/script&gt;</p>
<p><strong>Add this code in the table where you want to display the image. Here six tumbnail images are displayed. On selecting the thumbnail image a large image will be displayed. </strong></p>
<p><strong>Include this code in the php page where you want to display the image gallary.</strong></p>
<p>&lt;table&gt;&lt;tr&gt;<br />
&lt;td&gt;&lt;img id=&#8221;placeholder&#8221; src=&#8221;hotel_images/&lt;?php echo $row_hot['hotel_image1']?&gt;&#8221; border=&#8221;0&#8243; width=&#8221;500&#8243; height=&#8221;250&#8243; /&gt;&lt;/td&gt;</p>
<p>&lt;/tr&gt;</p>
<p>&lt;tr&gt;<br />
&lt;td align=&#8221;center&#8221;&gt;&lt;a onClick=&#8221;toggleMe(&#8216;para1&#8242;);return showPic(this);&#8221; href=&#8221;&lt;?php echo &#8220;hotel_images/&#8221;.$row_hot['hotel_image1'];?&gt;&#8221; &gt;&lt;?php if($row_hot['hotel_image1'] != &#8220;&#8221;){<br />
?&gt;&lt;img style=&#8221;border:none; padding-top:2px&#8221; src=&#8217;&lt;?php echo &#8220;hotel_images/&#8221;.$row_hot['hotel_image1'];?&gt;&#8217;  alt=&#8221;" width=&#8221;100&#8243; height=&#8221;50&#8243;&gt;&lt;?php } ?&gt;&lt;/a&gt;<br />
&lt;/td&gt;<br />
&lt;td align=&#8221;center&#8221;&gt;&lt;a onClick=&#8221;return showPic(this)&#8221; href=&#8221;&lt;?php echo &#8220;hotel_images/&#8221;.$row_hot['hotel_image2'];?&gt;&#8221;&gt;&lt;?php if($row_hot['hotel_image2'] != &#8220;&#8221;){<br />
?&gt;&lt;img style=&#8221;border:none; padding-top:2px&#8221; src=&#8217;&lt;?php echo &#8220;hotel_images/&#8221;.$row_hot['hotel_image2'];?&gt;&#8217; alt=&#8221;" width=&#8221;100&#8243; height=&#8221;50&#8243;&gt;&lt;?php } ?&gt;&lt;/a&gt;     &lt;/td&gt;<br />
&lt;/tr&gt;</p>
<p>&lt;tr&gt;<br />
&lt;td align=&#8221;center&#8221;&gt;&lt;a onClick=&#8221;toggleMe(&#8216;para1&#8242;);return showPic(this);&#8221; href=&#8221;&lt;?php echo &#8220;hotel_images/&#8221;.$row_hot['hotel_image3'];?&gt;&#8221; &gt;&lt;?php if($row_hot['hotel_image3'] != &#8220;&#8221;){<br />
?&gt;&lt;img style=&#8221;border:none; padding-top:2px&#8221; src=&#8217;&lt;?php echo &#8220;hotel_images/&#8221;.$row_hot['hotel_image3'];?&gt;&#8217;  alt=&#8221;" width=&#8221;100&#8243; height=&#8221;50&#8243;&gt;&lt;?php } ?&gt;&lt;/a&gt;     &lt;/td&gt;<br />
&lt;td align=&#8221;center&#8221;&gt;&lt;a onClick=&#8221;return showPic(this)&#8221; href=&#8221;&lt;?php echo &#8220;hotel_images/&#8221;.$row_hot['hotel_image4'];?&gt;&#8221;&gt;&lt;?php if($row_hot['hotel_image4'] != &#8220;&#8221;){<br />
?&gt;&lt;img style=&#8221;border:none; padding-top:2px&#8221; src=&#8217;&lt;?php echo &#8220;hotel_images/&#8221;.$row_hot['hotel_image4'];?&gt;&#8217; alt=&#8221;" width=&#8221;100&#8243; height=&#8221;50&#8243;&gt;&lt;?php } ?&gt;&lt;/a&gt;     &lt;/td&gt;<br />
&lt;/tr&gt;</p>
<p>&lt;tr&gt;<br />
&lt;td align=&#8221;center&#8221;&gt;<br />
&lt;a onClick=&#8221;toggleMe(&#8216;para1&#8242;);return showPic(this);&#8221; href=&#8221;&lt;?php echo &#8220;hotel_images/&#8221;.$row_hot['hotel_image5'];?&gt;&#8221; &gt;&lt;?php if($row_hot['hotel_image5'] != &#8220;&#8221;){<br />
?&gt;&lt;img style=&#8221;border:none; padding-top:2px&#8221; src=&#8217;&lt;?php echo &#8220;hotel_images/&#8221;.$row_hot['hotel_image5'];?&gt;&#8217;  alt=&#8221;" width=&#8221;100&#8243; height=&#8221;50&#8243;&gt;&lt;?php } ?&gt;&lt;/a&gt;     &lt;/td&gt;<br />
&lt;td align=&#8221;center&#8221;&gt;&lt;a onClick=&#8221;return showPic(this)&#8221; href=&#8221;&lt;?php echo &#8220;hotel_images/&#8221;.$row_hot['hotel_image6'];?&gt;&#8221;&gt;&lt;?php if($row_hot['hotel_image6'] != &#8220;&#8221;){<br />
?&gt;&lt;img style=&#8221;border:none; padding-top:2px&#8221; src=&#8217;&lt;?php echo &#8220;hotel_images/&#8221;.$row_hot['hotel_image6'];?&gt;&#8217; alt=&#8221;" width=&#8221;100&#8243; height=&#8221;50&#8243;&gt;&lt;?php } ?&gt;&lt;/a&gt;     &lt;/td&gt;<br />
&lt;/tr&gt;</p>
<p>&lt;/table</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/odedranilesh.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/odedranilesh.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/odedranilesh.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/odedranilesh.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/odedranilesh.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/odedranilesh.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/odedranilesh.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/odedranilesh.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/odedranilesh.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/odedranilesh.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/odedranilesh.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/odedranilesh.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/odedranilesh.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/odedranilesh.wordpress.com/77/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=odedranilesh.wordpress.com&amp;blog=7292930&amp;post=77&amp;subd=odedranilesh&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://odedranilesh.wordpress.com/2009/11/02/javascript-lightbox-image/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/501803e3b68d6d613b93b6f305f877ab?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">odedranilesh</media:title>
		</media:content>
	</item>
		<item>
		<title>Zend Files</title>
		<link>http://odedranilesh.wordpress.com/2009/07/22/zend-files/</link>
		<comments>http://odedranilesh.wordpress.com/2009/07/22/zend-files/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 05:40:56 +0000</pubDate>
		<dc:creator>Nilesh Odedra</dc:creator>
				<category><![CDATA[Interview Questions]]></category>

		<guid isPermaLink="false">http://odedranilesh.wordpress.com/?p=71</guid>
		<description><![CDATA[Index file for Zend index.php &#60;?php ini_set(&#8216;max_execution_time&#8217;,600); $lib_paths = array(); $lib_paths[] = &#8220;../application/&#8221;; $lib_paths[] = &#8220;../library/&#8221;; $inc_path = implode(PATH_SEPARATOR, $lib_paths); set_include_path($inc_path); include_once(&#8216;../application/bootstrap.php&#8217;); include_once(&#8216;../library/Zend/Loader.php&#8217;); //include_once(&#8216;../library/Zend/Filter/Input.php&#8217;); Zend_Loader::registerAutoload(); try {     $frontController = Zend_Controller_Front::getInstance();     $frontController-&#62;throwExceptions(true);     $frontController-&#62;setControllerDirectory(&#8216;../application/controllers/&#8217;);     $frontController -&#62;setParam(&#8216;noErrorHandler&#8217;, true);  //$this-&#62;input = new Input;     $frontController-&#62;dispatch(); } catch (Exception $exp) {     $contentType = &#8216;text/html&#8217;;     [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=odedranilesh.wordpress.com&amp;blog=7292930&amp;post=71&amp;subd=odedranilesh&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Index file for Zend<br />
index.php</p>
<p>&lt;?php<br />
ini_set(&#8216;max_execution_time&#8217;,600);<br />
$lib_paths = array();<br />
$lib_paths[] = &#8220;../application/&#8221;;<br />
$lib_paths[] = &#8220;../library/&#8221;;</p>
<p>$inc_path = implode(PATH_SEPARATOR, $lib_paths);<br />
set_include_path($inc_path);</p>
<p>include_once(&#8216;../application/bootstrap.php&#8217;);<br />
include_once(&#8216;../library/Zend/Loader.php&#8217;);<br />
//include_once(&#8216;../library/Zend/Filter/Input.php&#8217;);<br />
Zend_Loader::registerAutoload();</p>
<p>try<br />
{<br />
    $frontController = Zend_Controller_Front::getInstance();<br />
    $frontController-&gt;throwExceptions(true);<br />
    $frontController-&gt;setControllerDirectory(&#8216;../application/controllers/&#8217;);<br />
    $frontController -&gt;setParam(&#8216;noErrorHandler&#8217;, true);<br />
 //$this-&gt;input = new Input;<br />
    $frontController-&gt;dispatch();<br />
} catch (Exception $exp) {<br />
    $contentType = &#8216;text/html&#8217;;<br />
    header(&#8220;Content-Type: $contentType; charset=utf-8&#8243;);<br />
    echo &#8216;an unexpected error occured.&#8217;;<br />
    echo &#8216;&lt;h2&gt;Unexpected Exception: &#8216; . $exp-&gt;getMessage() . &#8216;&lt;/h2&gt;&lt;br /&gt;&lt;pre&gt;&#8217;;<br />
    echo $exp-&gt;getTraceAsString();<br />
}</p>
<p> </p>
<p>Bootstrap file for zend</p>
<p>bootstrap.php</p>
<p>&lt;?php<br />
//require_once (&#8216;../library/Zend/Loader.php&#8217;);<br />
include_once(&#8216;../library/Zend/Loader.php&#8217;);<br />
Zend_Loader::loadClass(&#8216;Zend_Cache&#8217;);<br />
Zend_Loader::loadClass(&#8216;Zend_Db&#8217;);<br />
Zend_Loader::loadClass(&#8216;Zend_Db_Table&#8217;);<br />
Zend_Loader::loadClass(&#8216;Zend_Config_Ini&#8217;);</p>
<p>class Globals<br />
{<br />
   <br />
    private static $_db       = null;<br />
    private static $_cache    = null;<br />
    private static $_config   = null;<br />
 <br />
   <br />
    static public function getDBConnection()<br />
    {<br />
        if (self::$_db != null) {<br />
            return self::$_db;<br />
        } // if (self::$_db != null)<br />
       <br />
        self::$_db = Zend_Db::factory(&#8216;Pdo_Mysql&#8217;,<br />
                                      array (&#8216;host&#8217;     =&gt; self::getConfig()-&gt;db-&gt;host,<br />
                                             &#8216;username&#8217; =&gt; self::getConfig()-&gt;db-&gt;username,<br />
                                             &#8216;password&#8217; =&gt; self::getConfig()-&gt;db-&gt;password,<br />
                                             &#8216;dbname&#8217;   =&gt; self::getConfig()-&gt;db-&gt;dbname));<br />
        Zend_Db_Table::setDefaultAdapter(self::$_db);<br />
        return self::$_db;<br />
    }<br />
    static public function getCache()<br />
    {<br />
        if (self::$_cache != null) {<br />
            return self::$_cache;<br />
        } // if (self::$_db != null)<br />
       <br />
      self::$_cache =  Zend_Cache::factory(&#8216;Core&#8217;,<br />
                                           &#8216;File&#8217;,<br />
                                            array(&#8216;lifeTime&#8217;=&gt;600,<br />
                                                  &#8216;automatic_serialization&#8217;=&gt;true),<br />
                                                  array(&#8216;cache_dir&#8217;=&gt;self::getConfig()-&gt;dirs-&gt;cache));<br />
   <br />
        return self::$_cache;<br />
    }</p>
<p>    public static function getConfig()<br />
    {<br />
        if (self::$_config != null) {<br />
            return self::$_config;<br />
        }<br />
       <br />
        self::$_config = new Zend_Config_Ini(<br />
            dirname(__FILE__) . DIRECTORY_SEPARATOR . &#8216;config.ini&#8217;,<br />
            &#8216;main&#8217;,<br />
            true);<br />
       <br />
        return self::$_config;<br />
    }</p>
<p>} // class Globals</p>
<p> </p>
<p>// Shopping cart</p>
<p>&lt;?<br />
session_start();</p>
<p>if($_SESSION['cart'] == &#8220;&#8221;)<br />
{<br />
  $_SESSION['cart'] = $_REQUEST['pid'];<br />
  $_SESSION['qtt']  = &#8220;1#&#8221;.$_REQUEST['pid'];<br />
echo &#8220;&lt;a href=&#8217;home.php?p=cart_det&#8217; &gt;View Your Cart&lt;/a&gt;&amp;nbsp;|&amp;nbsp;&lt;a href=&#8217;home.php?p=sell_prod&amp;r=5&#8242;&gt;Remove Cart&lt;/a&gt;&#8221;;<br />
}else<br />
{<br />
  $arr_list_prod = explode(&#8220;,&#8221;,$_SESSION['cart']); //conver the coma separeted sentence to array named &#8216;arr_list_prod&#8217;<br />
  $arr_list_prod = array_unique($arr_list_prod); //To remove duplicate values from array &#8216;arr_list_prod&#8217;</p>
<p>  if(!in_array($_REQUEST['pid'],$arr_list_prod))<br />
  {<br />
  $_SESSION['cart'] = implode(&#8220;,&#8221;,$arr_list_prod);   <br />
  $_SESSION['cart'] = $_SESSION['cart'].&#8221;,&#8221;.$_REQUEST['pid'];</p>
<p>  $_SESSION['qtt']  = $_SESSION['qtt'] .&#8221;,1#&#8221;.$_REQUEST['pid'];<br />
  }<br />
echo &#8220;&lt;a href=&#8217;home.php?p=cart_det&#8217; &gt;View Your Cart&lt;/a&gt;&amp;nbsp;|&amp;nbsp;&lt;a href=&#8217;home.php?p=sell_prod&amp;r=5&#8242;&gt;Remove Cart&lt;/a&gt;&#8221;;<br />
}<br />
?&gt;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/odedranilesh.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/odedranilesh.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/odedranilesh.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/odedranilesh.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/odedranilesh.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/odedranilesh.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/odedranilesh.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/odedranilesh.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/odedranilesh.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/odedranilesh.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/odedranilesh.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/odedranilesh.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/odedranilesh.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/odedranilesh.wordpress.com/71/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=odedranilesh.wordpress.com&amp;blog=7292930&amp;post=71&amp;subd=odedranilesh&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://odedranilesh.wordpress.com/2009/07/22/zend-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/501803e3b68d6d613b93b6f305f877ab?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">odedranilesh</media:title>
		</media:content>
	</item>
	</channel>
</rss>
