<?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>All About Web &#38; Mobile Application Development &#187; PHP</title>
	<atom:link href="http://www.londatiga.net/category/it/programming/programming-programming-it/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.londatiga.net</link>
	<description>All About Web &#38; Mobile Application Development</description>
	<lastBuildDate>Sat, 14 Jan 2012 16:56:37 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>How to Set Time Zone in PHP and MySQL</title>
		<link>http://www.londatiga.net/it/programming/programming-programming-it/how-to-set-time-zone-on-php-and-mysql/</link>
		<comments>http://www.londatiga.net/it/programming/programming-programming-it/how-to-set-time-zone-on-php-and-mysql/#comments</comments>
		<pubDate>Sat, 27 Nov 2010 05:10:14 +0000</pubDate>
		<dc:creator>lorenz</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[hosting]]></category>
		<category><![CDATA[Mysql]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[timezone]]></category>
		<category><![CDATA[vps]]></category>

		<guid isPermaLink="false">http://www.londatiga.net/?p=673</guid>
		<description><![CDATA[Sometimes when working with PHP-MySQL application, we have to explicitly set the time zone in our application in order to match the client&#8217;s time zone. Since PHP 5.3, time zone setting is mandatory and have to be set explicitly in application or in PHP configuration file (php.ini, for global used) or you will get PHP [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes when working with PHP-MySQL application, we have to explicitly set the time zone in our application in order to match the client&#8217;s time zone. Since <a title="PHP" href="http://www.php.net" target="_blank">PHP 5.3</a>, time zone setting is mandatory and have to be set explicitly in application or in PHP configuration file (<em>php.ini</em>, for global used) or you will get PHP warning message &#8216; <em><span style="color: #ff0000;">It is not safe to rely on the system&#8217;s timezone settings. bla bla bla</span></em>&#8216;. I faced this problem when moved my application from my old server to a new <a title="VPS Server" href="http://en.wikipedia.org/wiki/Virtual_private_server" target="_blank">VPS </a>server located overseas with different time zone. Since my old server running PHP 5.1 and located on the same time zone with my clients, i had no problem with time zone before.</p>
<p>So there are two ways to set time zone in PHP</p>
<p>1. For global scope, add <strong>date.timezone</strong> parameter in <em>php.ini</em> file</p>
<p>ex: <span style="color: #339966;"><strong><span style="color: #008000;">date.timezone = Asia/Jakarta</span></strong></span></p>
<p>Note: you need to restart web server to apply the changes</p>
<p>2. For local application scope, add <strong>date_default_timezone_set()</strong> function in PHP script</p>
<p>ex: <strong><span style="color: #008000;">date_default_timezone_set(&#8221;Asia/Jakarta&#8221;);</span></strong></p>
<p>Just like in PHP, we can also set time zone on<a title="MySQL" href="http://dev.mysql.com/doc/refman/5.1/en/time-zone-support.html" target="_blank"> MySQL</a> server that differs with system&#8217;s default time zone . It can be done at runtime or at startup. Note that by default MySQL uses system/server time zone.</p>
<p>1.  To set time zone at startup, append <strong>&#8211;timezone=timezonename</strong> option to <em>mysqld_safe</em></p>
<p>ex:</p>
<p>-<strong><span style="color: #008000;">-timezone=Asia/Jakarta </span></strong>or</p>
<p><strong><span style="color: #008000;">&#8211;timezone=+00:07</span></strong> ( note  &#8217;+0:07&#8242;  indicates the offset from GMT)</p>
<p>or from MySQL configuration file (<em>my.cnf</em>), add <strong>default-time-zone=&#8217;timezone&#8217; </strong>at <em>[myqld]</em> section.</p>
<p>ex:</p>
<p><strong><span style="color: #008000;">default-time-zone=&#8217;Asia/Jakarta&#8217;</span></strong></p>
<p>Using this way, the settings will be applied to all MySQL connections since startup.</p>
<p>2. To set time zone at runtime and applied to all connections, use<strong> SET GLOBAL time_zone = timezone</strong></p>
<p>ex:</p>
<p><strong><span style="color: #008000;">mysql&gt;SET GLOBAL time_zone = &#8216;+0:07&#8242;</span></strong></p>
<p>3. To set timezone at runtime per connection (session), use <strong>SET time_zone=timezone</strong></p>
<p>ex:</p>
<p><strong><span style="color: #008000;">mysql&gt;SET time_zone=&#8217;Asia/Jakarta&#8217;</span></strong></p>
<p>To check the global and session timezone:</p>
<p><strong><span style="color: #008000;">mysql&gt;SELECT @@global.time_zone, @@session.time_zone</span></strong></p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">select @@global.time_zone, @@session.time_zone;</div>
]]></content:encoded>
			<wfw:commentRss>http://www.londatiga.net/it/programming/programming-programming-it/how-to-set-time-zone-on-php-and-mysql/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to Get Video Thumbnail and Duration Using Mplayer and PHP</title>
		<link>http://www.londatiga.net/it/programming/how-to-get-video-thumbnail-and-duration-using-mplayer-and-php/</link>
		<comments>http://www.londatiga.net/it/programming/how-to-get-video-thumbnail-and-duration-using-mplayer-and-php/#comments</comments>
		<pubDate>Sat, 13 Feb 2010 09:39:22 +0000</pubDate>
		<dc:creator>lorenz</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[get video duration]]></category>
		<category><![CDATA[get video thumbnail]]></category>
		<category><![CDATA[mplayer]]></category>
		<category><![CDATA[video gallery]]></category>
		<category><![CDATA[video player]]></category>
		<category><![CDATA[video player php]]></category>

		<guid isPermaLink="false">http://www.londatiga.net/?p=511</guid>
		<description><![CDATA[Mplayer is a free and open source media player that available for all major operating systems including Windows, Unix and Mac OS X. Basically Mplayer is a command line application but it also has GUI front end that differs to its supported operating system.
In PHP, we can execute Mplayer&#8217;s command line to get thumbnail and [...]]]></description>
			<content:encoded><![CDATA[<p><a title="MPlayer" href="http://www.mplayerhq.hu/" target="_blank">Mplayer</a> is a free and open source media player that available for all major operating systems including Windows, Unix and Mac OS X. Basically Mplayer is a command line application but it also has GUI front end that differs to its supported operating system.</p>
<p>In PHP, we can execute Mplayer&#8217;s command line to get thumbnail and duration of a video file.</p>
<p><span style="text-decoration: underline;">The basic command line to get thumbnail is:</span></p>
<p>[lorenz@localhost] mplayer -ss <span style="color: #800000;"><em>&lt;position&gt;</em></span> <span style="color: #800000;"><em>videofile</em></span> &#8211; frames <span style="color: #800000;"><em>&lt;numofthumb&gt;</em></span> -nosound -vo jpeg<span style="color: #800000;">&lt;</span>:<span style="color: #800000;"><em>outdir=path/to/outdir</em></span><span style="color: #800000;">&gt;</span>.</p>
<p>where:</p>
<p><span style="color: #800000;">position</span>, is seek position in seconds or in hh:mm:ss when the thumbnail is taken<br />
<span style="color: #800000;"> videofile</span>, is the video file or path to video file<br />
<span style="color: #800000;"> numbofthumb</span>,  is the number of thumbnail created<br />
<span style="color: #800000;"> <img src='http://www.londatiga.net/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> utdir=path/to/outdir</span>, is the output directory. If the outdir is not specified, the default current working directory will be the output directory, make sure the output directory is writetable.</p>
<p>Example</p>
<p>[lorenz@localhost] mplayer -ss <span style="color: #800000;"><span style="color: #000000;">10</span></span><span style="color: #000000;"> video.flv</span> -frames 1<span style="color: #800000;"><em> </em></span>-nosound -vo jpe<span style="color: #800000;"><span style="color: #000000;">g:outdir=/home/lorenz/video</span></span></p>
<p>The command above will create one thumbnail from video.flv at 10th second position, the output directory is /home/lorenz/video. The resulted thumbnail filename will be 00000001.jpg and will increase in accordance with number of thumbnail created, -frames 10 will result ten thumbnails with filename starts from 00000001.jpg to 00000010.jpg.</p>
<p>To execute in PHP, use <em><span style="color: #800000;">exec <span style="font-style: normal;"><span style="color: #000000;">command</span></span></span></em></p>
<pre class="brush: php; title: ;">
exec(&quot;mplayer -ss 10 video.flv -frames 1 -nosound -vo jpeg:outdir=/home/lorenz&quot;);
</pre>
<p><span style="text-decoration: underline;">The basic command line to get duration is:</span></p>
<p>[lorenz@localhost] mplayer -vo null -ao null -frames 0 -identify video.flv</p>
<p>The command above will output a lot of video information, the video duration is on <span style="color: #800000;"><em>ID_LENGTH=duration</em></span> line.<br />
To get the duration in PHP, we have to extract ID_LENGTH line from the output string.<br />
The PHP code :</p>
<pre class="brush: php; title: ;">
exec('mplayer -vo null -ao null -frames 0 -identify video.flv', $output);

while (list($key, $value) = each($output)) {
      if ($length = strstr($v, &quot;ID_LENGTH=&quot;)) break;
}

$data       = explode('=', $length);
$duration   = $data [1];
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.londatiga.net/it/programming/how-to-get-video-thumbnail-and-duration-using-mplayer-and-php/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to Empty All Tables in a MySQL Database with PHP</title>
		<link>http://www.londatiga.net/it/how-to-empty-all-tables-in-a-mysql-database-with-php/</link>
		<comments>http://www.londatiga.net/it/how-to-empty-all-tables-in-a-mysql-database-with-php/#comments</comments>
		<pubDate>Tue, 26 Jan 2010 10:31:00 +0000</pubDate>
		<dc:creator>lorenz</dc:creator>
				<category><![CDATA[Information Technology]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[empty table mysql]]></category>
		<category><![CDATA[Mysql]]></category>
		<category><![CDATA[show tables]]></category>
		<category><![CDATA[truncate table]]></category>

		<guid isPermaLink="false">http://www.londatiga.net/?p=334</guid>
		<description><![CDATA[This is a simple PHP script to empty all tables in a MySQL database. This script first will list all tables in a database using &#8216;SHOW TABLES&#8216; statement then it will empty  each table using  &#8217;TRUNCATE TABLE&#8216; statement.

$con = mysql_connect('dbhost','dbuser','dbpassword');

if (!$con) die(&#34;Can't connect to database!&#34;);

mysql_select_db('dbname');

$res = mysql_query('SHOW TABLES', $con);

while ($row = mysql_fetch_array($res, MYSQL_NUM))
{
  $res2 [...]]]></description>
			<content:encoded><![CDATA[<p>This is a simple <a title="PHP" href="http://www.php.net" target="_blank">PHP</a> script to empty all tables in a <a title="MySQL" href="http://www.mysql.com" target="_blank">MySQL</a> database. This script first will list all tables in a database using &#8216;<span style="color: #800000;">SHOW TABLES</span>&#8216; statement then it will empty  each table using  &#8217;<span style="color: #800000;">TRUNCATE TABL</span><span style="color: #800000;">E</span>&#8216; statement.</p>
<pre class="brush: php; title: ;">
$con = mysql_connect('dbhost','dbuser','dbpassword');

if (!$con) die(&quot;Can't connect to database!&quot;);

mysql_select_db('dbname');

$res = mysql_query('SHOW TABLES', $con);

while ($row = mysql_fetch_array($res, MYSQL_NUM))
{
  $res2 = mysql_query(&quot;TRUNCATE TABLE `$row[0]`&quot;, $con);
}
</pre>
<p><span style="text-decoration: underline;">About TRUNCATE Statement</span></p>
<p>For an InnoDB table before version 5.0.3, InnoDB processes <span style="color: #800000;">TRUNCATE TABLE</span> by deleting rows one by one. As of MySQL 5.0.3, row by row deletion is used only if there are any<span style="color: #800000;"><span style="color: #000000;"> </span><span style="color: #000000;">foreign key</span></span> constraints that reference the table. If there are no <span style="color: #000000;">foreign key </span>constraints, InnoDB performs fast truncation by dropping the original table and creating an empty one with the same definition, which is much faster than deleting rows one by one.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.londatiga.net/it/how-to-empty-all-tables-in-a-mysql-database-with-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to Create Scrollable Image Slider Using JavaScript</title>
		<link>http://www.londatiga.net/featured-articles/how-to-create-scrollable-image-slider-using-javascript/</link>
		<comments>http://www.londatiga.net/featured-articles/how-to-create-scrollable-image-slider-using-javascript/#comments</comments>
		<pubDate>Sat, 23 Jan 2010 04:07:56 +0000</pubDate>
		<dc:creator>lorenz</dc:creator>
				<category><![CDATA[Featured Articles]]></category>
		<category><![CDATA[Java Script]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[image slider]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[scrollable]]></category>
		<category><![CDATA[scrollable image gallery]]></category>
		<category><![CDATA[scrollable images]]></category>
		<category><![CDATA[scrolling image]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[user interface]]></category>

		<guid isPermaLink="false">http://www.londatiga.net/?p=286</guid>
		<description><![CDATA[Scrollable image slider  is one of the interesting features in the image gallery application. This allows us to display thumbnails in the form of slides that can be scrolled automatically or manually using the control buttons.
Figure below shows a scrollable image slider featuring four thumbnails per slide. To display thumbnails from another slide, simply by [...]]]></description>
			<content:encoded><![CDATA[<p>Scrollable image slider  is one of the interesting features in the image gallery application. This allows us to display thumbnails in the form of slides that can be scrolled automatically or manually using the control buttons.</p>
<p><span title="Gambar di bawah ini menunjukkan sebuah Ren yang menampilkan empat gambar per slide, untuk menampilan gambar dari slide lain, hanya dengan mengklik tombol navigasi yang terdapat di kanan dan kiri slide.">Figure below shows a scrollable image slider featuring four thumbnails per slide. To display thumbnails from another slide, simply by clicking the navigation buttons located on the right and left slide. </span><span title="Slide juga dapat digerakkan secara otomatis menggunakan panah kiri dan kanan keybord atau menggunakan mouse wheel.">Slides can also be scrolled automatically by using the  left and right arrow keyboard or using  the mouse wheel.</span></p>
<div class="wp-caption aligncenter" style="width: 510px"><img title="Scrollable image gallery" src="http://londatiga.net/images/scrollable/scrollable.jpg" alt="Scrollable image gallery" width="500" height="111" /><p class="wp-caption-text">Scrollable image slider</p></div>
<p>In this tutorial, i&#8217;ll use <a title="Scrollable component" href="http://flowplayer.org/tools/scrollable.html" target="_blank">Scrollable</a> component from <a title="jQuery Tools" href="http://flowplayer.org/tools/index.html" target="_blank">jQuery Tools</a> user interface (UI) library which is based on popular <a title="jQuery Framework" href="http://jquery.com" target="_blank">jQuery</a> javascript framework. Current version of jQuery Tools at the time of this writing is version<a title="Version 1.1.2" href="http://flowplayer.org/tools/release-notes/index.html" target="_blank"> 1.1.2</a>, which can be downloaded <a title="Download jQuery Tools" href="http://flowplayer.org/tools/download.html" target="_blank">here</a>. The library itself consists of six user interface components that can be easily combined:  <a href="http://flowplayer.org/tools/tabs.html" target="_blank">Tabs</a>, <a href="http://flowplayer.org/tools/tooltip.html" target="_blank">Tooltip</a>, <a href="http://flowplayer.org/tools/overlay.html" target="_blank">Overlay</a>, <a href="http://flowplayer.org/tools/scrollable.html" target="_blank">Scrollable</a>, <a href="http://flowplayer.org/tools/expose.html" target="_blank">Expose</a>, and <a href="http://flowplayer.org/tools/flashembed.html" target="_blank">Flashembed</a>.</p>
<p><strong><span style="text-decoration: underline;">How to Setup</span></strong></p>
<ul>
<li>Download <span style="color: #800000;">S</span><span style="color: #800000;"><span style="color: #800000;">c</span>rollable <span style="color: #000000;">component</span></span> from <a href="http://flowplayer.org/tools/download.html" target="_blank">download page</a> and save it as <span style="color: #800000;">jquery.tools.min.js</span>. You can download it with<span style="color: #800000;"> </span><span style="color: #000000;">jQuery</span> (v1.3.2)  as a single file (21.75 kb) or as a separated file (3.37 kb) if you already have<span style="color: #000000;"> </span><span style="color: #000000;">jQuery</span>.</li>
<p><img class="alignnone" title="Download scrollable ui library" src="http://londatiga.net/images/scrollable/download.jpg" alt="" width="500" height="354" /></p>
<li>Include the <span style="color: #800000;">jquery.tools.min.js</span> in the HEAD section of your HTML file</li>
<pre class="brush: xml; title: ;">
&lt;script src=&quot;scripts/jquery.tools.min.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
</pre>
<p>or</p>
<pre class="brush: xml; title: ;">
&lt;script src=&quot;scripts/jquery-1.3.2.min.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;scripts/jquery.tools.min.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
</pre>
</ul>
<p><strong><span style="text-decoration: underline;">Using Scrollable UI library</span></strong></p>
<p><strong>HTML Code</strong></p>
<pre class="brush: xml; title: ;">
&lt;a class=&quot;prevPage left&quot;&gt;&lt;/a&gt;
&lt;div class=&quot;scrollable&quot;&gt;
    &lt;div class=&quot;items&quot;&gt;
        &lt;!-- 1-4 --&gt;
        &lt;img src=&quot;http://londatiga.net/tutorials/scrollable/images/img1.jpg&quot; /&gt;
        &lt;img src=&quot;http://londatiga.net/tutorials/scrollable/images/img2.jpg&quot; /&gt;
        &lt;img src=&quot;http://londatiga.net/tutorials/scrollable/images/img3.jpg&quot; /&gt;
        &lt;img src=&quot;http://londatiga.net/tutorials/scrollable/images/img4.jpg&quot; /&gt;

        &lt;!-- 5-8 --&gt;
        &lt;img src=&quot;http://londatiga.net/tutorials/scrollable/images/img5.jpg&quot; /&gt;
        &lt;img src=&quot;http://londatiga.net/tutorials/scrollable/images/img6.jpg&quot; /&gt;
        &lt;img src=&quot;http://londatiga.net/tutorials/scrollable/images/img7.jpg&quot; /&gt;
        &lt;img src=&quot;http://londatiga.net/tutorials/scrollable/images/img8.jpg&quot; /&gt;

        &lt;!-- 10-12 --&gt;
        &lt;img src=&quot;http://londatiga.net/tutorials/scrollable/images/img9.jpg&quot; /&gt;
        &lt;img src=&quot;http://londatiga.net/tutorials/scrollable/images/img10.jpg&quot; /&gt;
        &lt;img src=&quot;http://londatiga.net/tutorials/scrollable/images/img11.jpg&quot; /&gt;
        &lt;img src=&quot;http://londatiga.net/tutorials/scrollable/images/img12.jpg&quot; /&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;a class=&quot;nextPage right&quot;&gt;&lt;/a&gt;
</pre>
<p>line 01:  element for left/prev  button.</p>
<p>line 02: root element (div) for the scrollable.</p>
<p>line 03: wrapper element.</p>
<p>line 04-20: scrollable images (will be displayed  four images per slide).</p>
<p>line 24: element for right/next button.</p>
<p><strong>CSS Code</strong></p>
<p><em>Scrollable</em></p>
<pre class="brush: css; title: ;">
.scrollable {
	background: #ccc;
	position: relative;
	overflow: hidden;
	width: 690px;
	height:145px;
	border:1px solid #ccc;
	-moz-border-radius:4px;
	-webkit-border-radius:4px;
}

.scrollable .items {
	width: 20000em;
	position: absolute;
	clear: both;
}

.scrollable img {
    opacity: 0.6;
	float:left;
	margin:15px 5px 15px 15px;
	background-color:#fff;
	cursor:pointer;
	width:150px;
	height:113px;
	-moz-border-radius:4px;
	-webkit-border-radius:4px;
}

.scrollable .active {
    opacity:1;
	border:2px solid #000;
	z-index:9999;
	position:relative;
}
</pre>
<p>line 01, style for  container element, the length and width depends on image size and how many images you want displayed per slide.</p>
<p>line 12, style for wrapper element.</p>
<p>line 18,  style for images in a slide.</p>
<p>line 30, style for selected image.</p>
<p><em>Navigation button (prev &amp; next)</em></p>
<pre class="brush: css; title: ;">
.scrollable { float:left; }

a.left, a.right {
	display: block;
	width: 18px;
	height: 18px;
	float: left;
	margin: 60px 10px;
	cursor: pointer;
}

a.right { background: url(scrollable/arrow/right.png) no-repeat;  clear:right; margin-right: 0px;}
a.right:hover  { background-position:0px -18px; }
a.right:active 	{ background-position:0px 0px; }

a.left	{ background: url(scrollable/arrow/left.png) no-repeat;  margin-left: 0px; }
a.left:hover  { background-position:0px -18px; }
a.left:active  { background-position:-0px 0px; }

a.disabled { visibility:hidden !important; }
</pre>
<p>line 01, allow next and  prev buttons placed on each side of the slide.</p>
<p>line 12,  set size and position of prev and next buttons.</p>
<p>line 16,  set background image for prev and next buttons.</p>
<p><span style="text-decoration: underline;">Javascript Code</span></p>
<pre class="brush: jscript; title: ;">
&lt;script&gt;
	$(function()  { $(&quot;div.scrollable&quot;).scrollable({size: 4}); });
&lt;/script&gt;
</pre>
<p><span style="color: #800000;">$(&#8221;div.scrollable&#8221;) </span>is a jQuery selector for scrollabe container. On example above, we set four images for each slide using configuration parameter &#8216;<span style="color: #800000;">size</span>&#8216;. Default value of <span style="color: #800000;">&#8217;size</span>&#8216; parameter is 5. You can learn more about the API of the Scrollable component on <a title="Scrollable API" href="http://flowplayer.org/tools/scrollable.html" target="_blank">this page</a>.</p>
<div style="padding:10px;background:#2dd354;"><a title="Scrollable live demo" href="http://londatiga.net/tutorials/scrollable" target="_blank">View Live Demo</a> | <a title="Download scrollable demo source code" href="http://londatiga.net/downloads/tutorial/scrollable.zip" target="_self">Download Example Source Code</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.londatiga.net/featured-articles/how-to-create-scrollable-image-slider-using-javascript/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>How to Crop Image Using JavaScript and PHP</title>
		<link>http://www.londatiga.net/it/how-to-crop-image-using-javascript-and-php/</link>
		<comments>http://www.londatiga.net/it/how-to-crop-image-using-javascript-and-php/#comments</comments>
		<pubDate>Wed, 30 Dec 2009 00:46:01 +0000</pubDate>
		<dc:creator>lorenz</dc:creator>
				<category><![CDATA[Featured Articles]]></category>
		<category><![CDATA[Information Technology]]></category>
		<category><![CDATA[Java Script]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[image crop]]></category>
		<category><![CDATA[image crop guide]]></category>
		<category><![CDATA[image crop howto]]></category>
		<category><![CDATA[image crop javascript]]></category>
		<category><![CDATA[image crop php]]></category>
		<category><![CDATA[image crop tutorial]]></category>
		<category><![CDATA[image cropping]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[php GD]]></category>
		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://www.londatiga.net/?p=250</guid>
		<description><![CDATA[Image cropping is a usefull feature in web application that allows user to crop an image on a web page and save it for later use. This feature is commonly used in user&#8217;s preferences tool for creating a profile image. User uploads an image from his local hardrive and then directly crop his desired part [...]]]></description>
			<content:encoded><![CDATA[<p>Image cropping is a usefull feature in web application that allows user to crop an image on a web page and save it for later use. This feature is commonly used in user&#8217;s preferences tool for creating a profile image. User uploads an image from his local hardrive and then directly crop his desired part  for used as his profile image without using an image editing software.</p>
<div class="wp-caption alignnone" style="width: 510px"><img title="Image Cropping" src="http://londatiga.net/images/imagecropping/imagecropping.jpg" alt="Image Cropping" width="500" height="375" /><p class="wp-caption-text">Image Cropping</p></div>
<p>Image cropping process can be separated into two separated process. The first process is  for acquaring  coordinates and dimensions of selected area of an image, which will be done in client side using JavaScript. The next is  process for creating a new image based on coordinates and dimensions from previously cropping process using PHP on server side. In this tutorial, i&#8217;ll use JavaScript <a href="http://www.defusion.org.uk/code/javascript-image-cropper-ui-using-prototype-scriptaculous/comment-page-27/" target="_blank">Image Cropper</a> library by David Spurr and PHP GD image processing functions.</p>
<p><strong>Client Side</strong></p>
<p>Image Cropper is an excellent JavaScript library written by David Spurr that makes image cropping easier. It allows us to crop an image using an interface with the same features and styling as found in commercial image editing software. It is based on <a href="http://www.prototypejs.org/" target="_blank">Prototype</a> JavaScript Framework and <a href="http://script.aculo.us/" target="_blank">Scriptaculous</a>.</p>
<p><span style="text-decoration: underline;">How to Setup</span></p>
<ol>
<li>Download the required library files</li>
<p>- <a href="http://www.prototypejs.org/download">Prototype Javascript Framework</a></p>
<p>- <a href="http://script.aculo.us/downloads">Scriptaculous (scriptaculous-js-1.8.3.zip)</a></p>
<p>- <a href="http://www.defusion.org.uk/code/javascript-image-cropper-ui-using-prototype-scriptaculous/download-zip/" target="_blank">Image Cropper (jsCropperUI-1.2.1.zip)</a></p>
<li>Extract <span style="color: #800000;">scriptaculous-js-1.8.3.zip <span style="color: #000000;"> </span></span> and copy <span style="color: #800000;">scriptaculous.js</span>, <span style="color: #800000;">builder.js</span>, <span style="color: #800000;">effect.js</span> and <span style="color: #800000;">dragdrop.js</span> from the extracted files into your web application directory.</li>
<li>Extract <span style="color: #800000;">jsCropperUI-1.2.1.zip</span> and copy <span style="color: #800000;">cropper.js, marqueeHoriz.gif, marqueeVert.gif, cropper.css</span> from the extracted files into your web application directory (  must reside in the same directory).</li>
<li>Include <span style="color: #800000;">Prototype.js</span>, <span style="color: #800000;">scriptaculous.js <span style="color: #000000;">and</span> </span><span style="color: #800000;">cropper.j</span><span style="color: #800000;">s</span> in the HEAD section of your HTML file.
<pre class="brush: xml; title: ;">
&lt;script src=&quot;scripts/prototype.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;scripts/scriptaculous.js?load=effects,builder,dragdrop&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;scripts/cropper.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
</pre>
</li>
</ol>
<p><span style="text-decoration: underline;">Using Image Cropper Library</span></p>
<p><span style="text-decoration: underline;">With  Dynamic Crop Preview</span></p>
<pre class="brush: jscript; title: ;">
&lt;script type=&quot;text/javascript&quot; charset=&quot;utf-8&quot;&gt;
Event.observe (
	window,
	'load',
	function() {
		new Cropper.ImgWithPreview(
			't3soeta',
			{
				minWidth: 200,
				minHeight: 100,
                ratioDim: { x: 200, y: 100 },
				displayOnInit: true,
				onEndCrop: saveCoords,
                onloadCoords: { x1: 0, y1: 0, x2: 200, y2: 100 },
                previewWrap: 'preview'
			}
		)
	}
);

function saveCoords (coords, dimensions)
{
	$( 'x1' ).value = coords.x1;
	$( 'y1' ).value = coords.y1;
	$( 'width' ).value = dimensions.width;
	$( 'height' ).value = dimensions.height;
}
&lt;/script&gt;

&lt;form action=&quot;saveCrop.php&quot; method=&quot;post&quot;&gt;
&lt;div style=&quot;width:750px&quot;&gt;
    &lt;div style=&quot;float:left&quot;&gt;
        &lt;img src=&quot;images/t3soeta.jpg&quot; id=&quot;t3soeta&quot; width=&quot;500&quot; height=&quot;375&quot; /&gt;
    &lt;/div&gt;
    &lt;div id=&quot;preview&quot; style=&quot;float:right;&quot;&gt;&lt;/div&gt;
    &lt;div style=&quot;clear:both&quot;&gt;&lt;/div&gt;
    &lt;input type=&quot;hidden&quot; name=&quot;x1&quot; id=&quot;x1&quot; value=&quot;&quot;&gt;
    &lt;input type=&quot;hidden&quot; name=&quot;y1&quot; id=&quot;y1&quot; value=&quot;&quot;&gt;
    &lt;input type=&quot;hidden&quot; name=&quot;width&quot; id=&quot;width&quot; value=&quot;&quot;&gt;
    &lt;input type=&quot;hidden&quot; name=&quot;height&quot; id=&quot;height&quot; value=&quot;&quot;&gt;
&lt;/div&gt;
&lt;input type=&quot;submit&quot; name=&quot;Done&quot; value=&quot; Done &quot;&gt;
&lt;/form&gt;
</pre>
<p><strong>Line 06:</strong> Instantiate Image Cropper class.</p>
<p><strong>Line 07:</strong> Image Id.</p>
<p><strong>Line 09:</strong> <span style="color: #800000;">minWidth</span>, is the minimum width for  selected area in pixels.</p>
<p><strong>Line 10</strong>: <span style="color: #800000;">minHeight</span>, is the minimum height for selected area in pixels.</p>
<p><strong>Line 11:</strong> <span style="color: #800000;">ratioDim</span>, is the pixel dimensions to apply as a restrictive ratio, with properties x &amp; y.</p>
<p><strong>Line 12: </strong><span style="color: #800000;">displayOnInit</span>, whether display the selected area on initialisation. If set to <span style="color: #800000;">true</span>, <span style="color: #800000;">minWidth</span> and <span style="color: #800000;">minHeight</span> or <span style="color: #800000;">ratioDim</span> must be provided.</p>
<p><strong>Line 13:</strong> o<span style="color: #800000;">nEndCrop</span>, a callback function which will be called when user finished a crop movement. The function takes two arguments:</p>
<ul>
<li>coords, is the coordinates of selected area with properties <span style="color: #800000;">x1</span>, <span style="color: #800000;">y1</span>, <span style="color: #800000;">x2</span>,  <span style="color: #800000;">y2</span>.</li>
<li>dimensions , is the dimensions of selected area with properties <span style="color: #800000;">w</span><span style="color: #800000;">idth</span> and<span style="color: #800000;"> height</span>.</li>
</ul>
<p>On example above (Line 21), coordinates and dimensions are stored in hidden elements and will be sent to server side script (<span style="color: #800000;">s</span><span style="color: #800000;">aveCrop.php</span>) using HTTP POST method for later processing .</p>
<p><strong>Line 14: </strong><span style="color: #800000;">onloadCoords<span style="color: #000000;">, is the coordinates of the selected area to display onload</span></span></p>
<p><strong>Line 15: </strong><span style="color: #800000;">previewWra</span><span style="color: #800000;">p</span>, is the id of container for image crop preview.</p>
<p><strong>Line 21: </strong>callback function, as set on <span style="color: #800000;">onEndCrop</span> option (Line 13).</p>
<p><strong>Line 33:</strong> image to be cropped, it&#8217;s id must match the id set on Line 07.</p>
<p><strong>Line 35: </strong>div container for image crop preview.</p>
<p><strong>Line 37-40</strong>: Hidden elements to store coordinates and dimensions of selected area.</p>
<p>View live demo <a title="Image Cropping" href="http://londatiga.net/tutorials/imagecrop/example.html" target="_blank">here</a></p>
<p><span style="text-decoration: underline;">Without Dynamic Crop Preview</span></p>
<p>For using Image Cropper without dynamic preview, change the class from <span style="color: #800000;">Cropper.ImgWithPrevie</span><span style="color: #800000;">w</span> to <span style="color: #800000;">Cropper.Img<span style="color: #000000;"> and remove the <span style="color: #800000;">previewWrap</span> option.</span></span></p>
<pre class="brush: jscript; title: ;">
Event.observe (
	window,
	'load',
	function() {
		new Cropper.Img (
			't3soeta',
			{
				minWidth: 200,
				minHeight: 100,
                ratioDim: { x: 200, y: 100 },
				displayOnInit: true,
				onEndCrop: saveCoords,
                onloadCoords: { x1: 0, y1: 0, x2: 200, y2: 100 },
			}
		)
	}
);
</pre>
<p><span style="color: #800000;"><span style="color: #000000;">View live demo <a title="Image Cropping" href="http://londatiga.net/tutorials/imagecrop/example2.html" target="_blank">here</a></span></span></p>
<p><span style="color: #800000;"><span style="color: #000000;"><strong>Server Side</strong></span></span></p>
<p>On server side, image is processed using PHP GD image functions, which required GD library installed.</p>
<pre class="brush: php; title: ;">
&lt;?php
$x1      = $_POST['x1'];
$y1      = $_POST['y1'];
$width   = $_POST['width'];
$height  = $_POST['height'];

$srcImg  = imagecreatefromjpeg('images/t3soeta.jpg');
$newImg  = imagecreatetruecolor($width, $height);

imagecopyresampled($newImg, $srcImg, 0, 0, $x1, $y1, $width, $height, $width, $height);

imagejpeg($newImg, 'images/cropped_t3soeta.jpg');
?&gt;
</pre>
<p><strong>Line 02-05: </strong>get coordinates and dimensions sent from client.</p>
<p><strong>Line 07:</strong> create source image</p>
<p><strong>Line 08:</strong> create a new true color image for cropped image</p>
<p><strong>Line 10:</strong> copy selected area from source image into new image using coordinates and dimensions sent from client.</p>
<p><strong>Line 12</strong>: Output the new cropped image into a file.</p>
<div style="padding:10px;background:#2dd354;"><a title="Download image crop demo source code" href="http://londatiga.net/downloads/tutorial/imagecrop.zip" target="_self">Download Example Source Code</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.londatiga.net/it/how-to-crop-image-using-javascript-and-php/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>How to Create Facebook Application with PHP for Beginner</title>
		<link>http://www.londatiga.net/it/how-to-create-facebook-application-with-php-for-beginner/</link>
		<comments>http://www.londatiga.net/it/how-to-create-facebook-application-with-php-for-beginner/#comments</comments>
		<pubDate>Sat, 05 Dec 2009 10:42:41 +0000</pubDate>
		<dc:creator>lorenz</dc:creator>
				<category><![CDATA[Featured Articles]]></category>
		<category><![CDATA[Information Technology]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[facebook application beginner]]></category>
		<category><![CDATA[facebook application howto]]></category>
		<category><![CDATA[facebook application php]]></category>
		<category><![CDATA[facebook application tutorial]]></category>
		<category><![CDATA[facebook tutorial beginner]]></category>
		<category><![CDATA[fbml]]></category>

		<guid isPermaLink="false">http://www.londatiga.net/?p=179</guid>
		<description><![CDATA[Facebook is the fastest growing social networking application that currently has more than 350 million active users. One of it&#8217;s key features is Facebook Platform, that enable us to build  applications on Facebook. Currently there are a lot of Facebook  applications built by developers around the world such as game, which is the most popular [...]]]></description>
			<content:encoded><![CDATA[<p>Facebook is the fastest growing social networking application that currently has more than 350 million active users. One of it&#8217;s key features is <span style="color: #003300;"><strong>Facebook Platform</strong></span>, that enable us to build  applications on Facebook. Currently there are a lot of Facebook  applications built by developers around the world such as game, which is the most popular application on Facebook.</p>
<p>This tutorial will guide you through the creation of a Facebook application using Facebook PHP API that will display Hello World text, called <span style="color: #003300;"><strong>Hola Mundo</strong></span>.  Before we begin to create Facebook application, there are a few things that you have to know:</p>
<ul>
<li>You should be familiar with PHP  programming language</li>
<li>You need to be familiar with web hosting fundamentals and have a place to deploy your application</li>
<li>You must have a Facebook account</li>
</ul>
<p>If you have meet the requirements above, you are ready to get started  building Facebook application through this tutorial.</p>
<p><strong>A. Setting Up Your Application</strong></p>
<ul>
<li>Go to <a title="Facebook Developers Area" href="http://www.facebook.com/developers" target="_blank">Facebook developers area</a>, and click <span style="color: #800000;"><span style="color: #003300;"><strong>Set Up New Applicatio</strong></span></span><span style="color: #003300;"><strong>n</strong></span> button</li>
</ul>
<div class="wp-caption alignnone" style="width: 560px"><img title="Facebook Developers Area" src="http://londatiga.net/images/facebook1/developer_area.jpg" alt="Facebook Developers Area" width="550" height="119" /><p class="wp-caption-text">Facebook Developers Area</p></div>
<ul>
<li>Type the application name (Hola  Mundo), choose<span style="color: #003300;"><strong> </strong></span><span style="color: #993300;"><span style="font-weight: normal;"><span style="color: #003300;"><strong>Agree</strong></span></span></span> on Facebook Term and then click <span style="color: #003300;"><strong>Create Application</strong></span> button</li>
</ul>
<div class="wp-caption alignnone" style="width: 560px"><img title="Create New Application" src="http://londatiga.net/images/facebook1/create_new_app.jpg" alt="Create New Application" width="550" height="206" /><p class="wp-caption-text">Create New Application</p></div>
<ul>
<li>Then Facebook will create two keys for your application, the API key and the secret key, write them and save on a file for later use.</li>
</ul>
<div class="wp-caption alignnone" style="width: 510px"><img title="Setup Application" src="http://londatiga.net/images/facebook1/edit_app1.jpg" alt="Setup Application" width="500" height="530" /><p class="wp-caption-text">Setup Application</p></div>
<ul>
<li>Go to <span style="color: #003300;"><strong>Canvas</strong></span> tab and type a unique URL for your application (hollamundo) on<span style="color: #993300;"><strong> </strong></span><strong><span style="color: #993300;"><span style="color: #003300;">Canvas Page URL</span></span>,</strong><strong> </strong>it must be unique or you&#8217;ll  get error message if the URL has been used by another application.  In this case i use hollamundo rather than holamundo because it has been used by another application. On <span style="color: #993300;"><span style="font-weight: normal;"><span style="color: #003300;"><strong>Canvas Callback</strong></span></span></span><span style="color: #003300;"><strong> </strong></span><span style="color: #003300;"><strong>URL</strong></span><strong>, </strong>type the URL for the application page on your server<strong> </strong>. Choose <span style="color: #993300;"><strong><span style="color: #003300;">FBML</span></strong></span> On <span style="color: #003300;"><strong>Render Method</strong></span> option under <span style="color: #993300;"><strong><span style="color: #003300;">Canvas Setting</span></strong><span style="color: #003300;"><strong>s</strong></span></span>,  which enables you to build full Facebook Platform applications that deeply integrate into a user&#8217;s Facebook experience. Let another setting options to it&#8217;s default then click <span style="color: #993300;"><strong><span style="color: #003300;">Save Changes</span></strong></span> button.</li>
</ul>
<div class="wp-caption alignnone" style="width: 560px"><img title="Canvas Settings" src="http://londatiga.net/images/facebook1/canvas_settings.jpg" alt="Canvas Settings" width="550" height="344" /><p class="wp-caption-text">Canvas Settings</p></div>
<ul>
<li>At this time your application is ready, try to type your<span style="color: #003300;"><strong> </strong></span><span style="color: #003300;"><strong>Canvas Page UR</strong></span><span style="color: #003300;"><strong>L</strong></span> on browser and see what the results. What you get is an error message because your application doesn&#8217;t exists on your server, ok don&#8217;t worry, lets go to next steps.</li>
</ul>
<p><strong>B. Configure Application on Your Host</strong></p>
<p>After configuring your application on Facebook, it&#8217;s time to do a little bit coding and some server administration tasks.</p>
<ul>
<li>Download <a title="Download CLient Library" href="http://svn.facebook.com/svnroot/platform/clients/packages/facebook-platform.tar.gz" target="_self">Facebook  Client Library</a> and extract it, you will find two directories inside,  <span style="color: #003300;"><strong>footprints</strong></span> and <span style="color: #993300;"><strong><span style="color: #003300;">php</span></strong></span>. Copy all files from <span style="color: #003300;"><strong>php</strong></span> directory and upload them to your facebook application directory on your server, that must be the same with <strong><span style="color: #993300;"><span style="color: #003300;">Canvas Callback UR</span></span><span style="font-weight: normal;"><span style="color: #003300;">L</span></span> </strong>you set before.</li>
<li>Create<span style="color: #008000;"> <span style="color: #993300;"><strong><span style="color: #003300;">index.php</span></strong></span></span> file with the following contents:</li>
</ul>
<pre class="brush: php; title: ;">
&lt;?php
include_once 'facebook.php';

$apikey    = 'typeyourapikeyhere';
$secretkey = 'typeyoursecretkeyhere';

$fbObj     = new Facebook($apikey, $secretkey);

$myuid     = $fbObj-&gt;require_login();

$fbml      = &quot;&lt;h2&gt;Hello world, my name is &lt;fb:name uid=\&quot;$myuid\&quot; useyou=\&quot;false\&quot; /&gt;,&quot;
           . &quot;welcome to my first facebook application!&lt;/h2&gt;&quot;;
echo $fbml;
?&gt;
</pre>
<p>Simple right ? Facebook has made it simple using FBML, all you have to do is apply the predifined tags on your code. You can read the complete explanation about FBML on Facebook Developers Wiki page <a title="Facebook Developers Wiki" href="http://wiki.developers.facebook.com/index.php/FBML" target="_blank">here</a> .</p>
<p><span style="color: #0000ff;"><strong>line 2</strong></span>:  include the facebook main library file</p>
<p><strong><span style="color: #0000ff;">line 4&amp;</span></strong><span style="color: #0000ff;"><strong>5</strong></span>:  define your api key and secret key</p>
<p><strong><span style="color: #0000ff;">line 7</span></strong>:  create an instance of Facebook client class</p>
<p><span style="color: #0000ff;"><strong>line 8</strong></span>:  get your facebook user id (uid),<span style="color: #800080;"> <span style="color: #000000;">the</span> <span style="color: #003300;"><strong>require_logi</strong></span><span style="color: #003300;"><strong>n</strong></span></span> method is used to force user to logged into Facebook before using the application. If they are not logged in, Facebook will redirect them to Facebook login page first and then brings them to your application page after they logged in.</p>
<p><strong><span style="color: #0000ff;">line 9</span></strong>:  your page content&#8217;s that display your name using FBML <a title="Fb:name tag" href="http://wiki.developers.facebook.com/index.php/Fb:name" target="_blank">Fb:name</a> tag.</p>
<p>Now your application is complete and ready to be accessed by anyone in the world. Type your <span style="color: #003300;"><strong>Canvas Page UR</strong></span><span style="color: #003300;"><strong>L</strong></span> on browser and you&#8217;ll get <span style="color: #993300;"><strong><span style="color: #003300;">Allow Access</span></strong></span> page which is default for Facebook application for the first time access, click <span style="color: #993300;"><strong><span style="color: #003300;">Allow</span></strong></span> button to access your application.</p>
<div class="wp-caption alignnone" style="width: 560px"><img class=" " title="Allow Access Page" src="http://londatiga.net/images/facebook1/allow_access.jpg" alt="Allow Access Page" width="550" height="228" /><p class="wp-caption-text">Allow Access Page</p></div>
<div class="wp-caption alignnone" style="width: 579px"><img title="Your Application Page" src="http://londatiga.net/images/facebook1/welcome.jpg" alt="Your Application Page" width="569" height="113" /><p class="wp-caption-text">Your Application Page</p></div>
<p>You can view live example application above <a title="Hello Mundo" href="http://apps.facebook.com/hollamundo" target="_blank">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.londatiga.net/it/how-to-create-facebook-application-with-php-for-beginner/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>How to Zip Files or Folder On The Fly Using PHP</title>
		<link>http://www.londatiga.net/it/programming/how-to-zip-files-or-folder-on-the-fly-using-php/</link>
		<comments>http://www.londatiga.net/it/programming/how-to-zip-files-or-folder-on-the-fly-using-php/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 16:39:04 +0000</pubDate>
		<dc:creator>lorenz</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[php zip directory]]></category>
		<category><![CDATA[php zip file]]></category>
		<category><![CDATA[zip]]></category>
		<category><![CDATA[zip directory]]></category>
		<category><![CDATA[zip folder php]]></category>
		<category><![CDATA[zip on the fly]]></category>
		<category><![CDATA[zip on the fly with php]]></category>
		<category><![CDATA[zip php]]></category>

		<guid isPermaLink="false">http://www.londatiga.net/?p=163</guid>
		<description><![CDATA[Sometimes in web programming when dealing with multiple files or directory download operations, it is better to serve the user with a single zip file rather than let the user manually download the file one by one using direct link download . To overcome this problem, we have to create a zip file on the [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes in web programming when dealing with multiple files or directory download operations, it is better to serve the user with a single zip file rather than let the user manually download the file one by one using direct link download . To overcome this problem, we have to <strong>create a zip file on the fly</strong> without have to manually create it using any commpresion tools or softwares.</p>
<p>PHP has some functions dealing with file compression that enables us to create zip file on the fly. In this tutorial i will use PHP <strong>CreateZipFile</strong> classs package from <a href="http://www.rochakchauhan.com/blog/">Rochak Chauhan</a>. I have made some examples below to explain how to craete zip file on the fly from multiple files or directory.</p>
<p>Example 1, create zip file from existing files:</p>
<pre class="brush: php; title: ;">
&lt;?php
include_once 'CreateZipFile.inc.php';

$createZip = new CreateZipFile;

$createZip-&gt;addDirectory('/');

$filecontent1 = file_get_contents('fileone.txt');
$filecontent2 = file_get_contents('filetwo.txt');

$createZip-&gt;addFile($filecontent1, '/fileone.txt');
$createZip-&gt;addFile($filecontent2, '/filetwo.txt');

$zipFileName = 'myzip.zip';
$handle       = fopen($zipFileName, 'wb');
$out           = fwrite($handle, $createZip-&gt;getZippedFile());

fclose($handle);

$createZip-&gt;forceDownload($zipFileName);

@unlink($zipFileName);
?&gt;
</pre>
<p>To create zip file:</p>
<ul>
<li>add a directory into zip file using <strong>addDirectory</strong> method</li>
<li>add files into directory using <strong>addFile</strong> method</li>
<li>create zip file temporary for download and delete it after the file is downloaded</li>
</ul>
<p>Example 2, create zip file for a directory with it&#8217;s contents/subdirectories</p>
<pre class="brush: php; title: ;">
&lt;?php
include_once 'CreateZipFile.inc.php';

$createZip = new CreateZipFile;

$createZip-&gt;zipDirectory('/testdir', '');

$zipFileName = 'myzip.zip';
$handle       = fopen($zipFileName, 'wb');
$out           = fwrite($handle, $createZip-&gt;getZippedFile());

fclose($handle);

$createZip-&gt;forceDownload($zipFileName);

@unlink($zipFileName);
?&gt;
</pre>
<p>To create zip file for a directory, use <strong>zipDirectory</strong> method that takes two arguments, first is the name of directory that want to be zipped and second is directory name for zipped file.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.londatiga.net/it/programming/how-to-zip-files-or-folder-on-the-fly-using-php/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>How to List A Directory Contents Using PHP (Recursive)</title>
		<link>http://www.londatiga.net/it/programming/how-to-list-a-directory-contents-using-php-recursive/</link>
		<comments>http://www.londatiga.net/it/programming/how-to-list-a-directory-contents-using-php-recursive/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 07:59:22 +0000</pubDate>
		<dc:creator>lorenz</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[directory]]></category>
		<category><![CDATA[directory list]]></category>
		<category><![CDATA[php directory content]]></category>
		<category><![CDATA[php directory list]]></category>
		<category><![CDATA[php directory tree]]></category>
		<category><![CDATA[recursive]]></category>
		<category><![CDATA[tree]]></category>

		<guid isPermaLink="false">http://www.londatiga.net/?p=156</guid>
		<description><![CDATA[To list contents of a directory is simple in PHP, just use three PHP directory functions, opendir,  readdir and is_dir.
The code:

&#60;?php
function listDirectory($path)
{
    $handle = @opendir($path);

    while (false !== ($file = readdir($handle))) {
        if ($file == '.' &#124;&#124; $file == '..') continue;

  [...]]]></description>
			<content:encoded><![CDATA[<p>To list contents of a directory is simple in PHP, just use three PHP directory functions, <strong>opendir</strong>,  <strong>readdir</strong> and<strong> is_dir</strong>.</p>
<p>The code:</p>
<pre class="brush: php; title: ;">
&lt;?php
function listDirectory($path)
{
    $handle = @opendir($path);

    while (false !== ($file = readdir($handle))) {
        if ($file == '.' || $file == '..') continue;

        if ( is_dir(&quot;$path/$file&quot;)) {
            echo &quot;$path/$file\n&quot;;
            listDirectory(&quot;$path/$file&quot;);
        } else {
            echo &quot;$path/$file\n&quot;;
        }
    }

    closedir($handle);
}

listDirectory(&quot;tutorials&quot;);
?&gt;
</pre>
<p>Here&#8217;s the result:</p>
<div class="wp-caption alignnone" style="width: 380px"><img title="Directory List Using PHP" src="http://londatiga.net/images/dirlist/dirlist.jpg" alt="Directory List Using PHP" width="370" height="161" /><p class="wp-caption-text">Directory List Using PHP</p></div>
<p><strong><span style="font-weight: normal;">To start list contents, first open the directory handle using <strong>opendir </strong>then loop to read the entire contents using <strong>readdir</strong>. Check if content is a directory or a file using <strong>is_dir</strong>, if a directory,  then call function listDirectory to read it&#8217;s content (recursive).</span></strong>TV6CA39U8TTG</p>
]]></content:encoded>
			<wfw:commentRss>http://www.londatiga.net/it/programming/how-to-list-a-directory-contents-using-php-recursive/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To Define Global Absolute Path in PHP</title>
		<link>http://www.londatiga.net/it/how-to-define-global-absolute-path-in-php/</link>
		<comments>http://www.londatiga.net/it/how-to-define-global-absolute-path-in-php/#comments</comments>
		<pubDate>Sat, 31 Oct 2009 09:14:27 +0000</pubDate>
		<dc:creator>lorenz</dc:creator>
				<category><![CDATA[Featured Articles]]></category>
		<category><![CDATA[Information Technology]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Absolute Path]]></category>
		<category><![CDATA[Relative path]]></category>

		<guid isPermaLink="false">http://www.londatiga.net/?p=75</guid>
		<description><![CDATA[A path is general form of a filename or directory that specified a unique location in a file system. In web programming, a path  is used to define links (url) to documents and images or to include a specified library file. There are two standard ways to define a path:

Absolute Path, is a path that [...]]]></description>
			<content:encoded><![CDATA[<p>A path is general form of a filename or directory that specified a unique location in a file system. In web programming, a path  is used to define links (url) to documents and images or to include a specified library file. There are two standard ways to define a path:</p>
<ol>
<li><strong>Absolute Path</strong>, is a path that points to the same location on file system regardless of the working directory or combined paths and usually written in reference to root directory.</li>
<li><strong>Relative Path</strong>, is a path  that relative to working directory.</li>
</ol>
<p>In many ways, absolute path is much usefull because it doesn&#8217;t need us to redefine the path or link if we change the working directory. For an example, below is a directory hierarchy of a web application that located on a development server  that can be accessd via url <span style="color: #0000ff;">www.mysite.com</span>, where <span style="color: #0000ff;">/var/www/html </span>is it&#8217;s web server&#8217;s document root and application root directory and &#8216;<span style="color: #0000ff;">/&#8217; <span style="color: #000000;">is the application root url</span></span>.</p>
<div class="wp-caption alignnone" style="width: 260px"><img title="Document Root" src="http://londatiga.net/images/docroot.jpg" alt="Document Root" width="250" height="181" /><p class="wp-caption-text">Document Root</p></div>
<p><span style="color: #0000ff;"><span style="color: #000000;">Take a look at<span style="color: #008000;"> index.php</span> in <span style="color: #0000ff;">profile</span> directory, to define an url to<span style="color: #008000;"> <span style="color: #339966;">mypic.jpg</span></span> in <span style="color: #0000ff;">images</span> directory and include <span style="color: #339966;">lib.php</span> from <span style="color: #0000ff;">lib</span> directory:<br />
</span></span></p>
<p><span style="color: #0000ff;"><span style="color: #000000;">using absolute path:<br />
</span></span></p>
<pre class="brush: php; title: ;">
&lt;?php
include '/var/www/html/lib/lib.php';

$str = '&lt;img src=&quot;/images/mypic.jpg&quot;&gt;';
?&gt;
</pre>
<p><span style="color: #0000ff;"><span style="color: #000000;">using relative path:<br />
</span></span></p>
<pre class="brush: php; title: ;">
&lt;?php
include '../../lib/lib.php';

$str = '&lt;img src=&quot;../../images/mypic.jpg&quot;&gt;';
?&gt;
</pre>
<p><span style="color: #0000ff;"><span style="color: #000000;">Using absolute path, it wouldn&#8217;t be a matter where the working directory is, but it would be a problem if  you change the application root directory into  another directory other than web server&#8217;s document root, for example in <span style="color: #0000ff;">/var/www/html/</span><span style="color: #0000ff;">web</span>, so your application would be accesed via <span style="color: #0000ff;">www.mysite.com/web</span>. We have to edit manually each file that using absolute path because the root directory will changed to <span style="color: #0000ff;">/var/www/html/</span><span style="color: #0000ff;">web</span> so the included file will not work.</span></span></p>
<p><span style="color: #0000ff;"><span style="color: #000000;">To overcome this problem, you have to define a global variable that specified absolute path that generally applied to all directories in your application. The  solution is to define two variables which will be used to define root directory for file operations and root url for url operations  in a file that would be placed in the root directory .</span></span></p>
<pre class="brush: php; title: ;">
&lt;?php
define('ROOT_DIR', dirname(__FILE__));
define('ROOT_URL', substr($_SERVER['PHP_SELF'], 0, - (strlen($_SERVER['SCRIPT_FILENAME']) - strlen(ROOT_DIR))));
?&gt;
</pre>
<p>Save it as init.php and place it in your application root directory.So, from our example above, using the two variables:</p>
<pre class="brush: php; title: ;">
&lt;?php
include '../../init.php';
include ROOT_DIR .  '/lib/lib.php';

$img = '&lt;img src=&quot;' .  ROOT_URL . '/images/my.pic.jpg&quot;&gt;';
?&gt;
</pre>
<p>As you can see, it will be applied in any directories regardless where the current working directory or server document root.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.londatiga.net/it/how-to-define-global-absolute-path-in-php/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

