<?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>fengcool.com &#187; rick</title>
	<atom:link href="http://www.fengcool.com/author/rick/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.fengcool.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Wed, 25 Jan 2012 19:09:58 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>untar all files in a directory</title>
		<link>http://www.fengcool.com/2012/01/untar-all-files-in-a-directory/</link>
		<comments>http://www.fengcool.com/2012/01/untar-all-files-in-a-directory/#comments</comments>
		<pubDate>Wed, 25 Jan 2012 19:09:40 +0000</pubDate>
		<dc:creator>rick</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[tar]]></category>
		<category><![CDATA[untar]]></category>

		<guid isPermaLink="false">http://www.fengcool.com/?p=186</guid>
		<description><![CDATA[for i in *.tar.gz; do echo extracting $i; tar xvzf $i ;
]]></description>
			<content:encoded><![CDATA[<p>for i in *.tar.gz; do echo extracting $i; tar xvzf $i ;</p>
<a rel="external nofollow" class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.fengcool.com%2F2012%2F01%2Funtar-all-files-in-a-directory%2F&amp;linkname=untar%20all%20files%20in%20a%20directory"><img src="http://www.fengcool.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Save/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.fengcool.com/2012/01/untar-all-files-in-a-directory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Open and edit files from remote server</title>
		<link>http://www.fengcool.com/2010/10/open-and-edit-files-from-remote-server/</link>
		<comments>http://www.fengcool.com/2010/10/open-and-edit-files-from-remote-server/#comments</comments>
		<pubDate>Tue, 19 Oct 2010 14:07:42 +0000</pubDate>
		<dc:creator>rick</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.fengcool.com/?p=168</guid>
		<description><![CDATA[In my workplace, every developer needs to work on own directory in a shared dev server. 
Here is the command I ran to open my directory and edit my files remotely.

1
sshfs username@192.168.0.6:/remote/directory/path /mount/to/your/local/directory/path

* 192.168.0.6 is IP of remote server.
After you ran this, access to /mount/to/your/local/directory/path directory is same as access to remote directory.
Have fun.  [...]]]></description>
			<content:encoded><![CDATA[<p>In my workplace, every developer needs to work on own directory in a shared dev server. </p>
<p>Here is the command I ran to open my directory and edit my files remotely.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">sshfs username<span style="color: #000000; font-weight: bold;">@</span>192.168.0.6:<span style="color: #000000; font-weight: bold;">/</span>remote<span style="color: #000000; font-weight: bold;">/</span>directory<span style="color: #000000; font-weight: bold;">/</span>path <span style="color: #000000; font-weight: bold;">/</span>mount<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>your<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>directory<span style="color: #000000; font-weight: bold;">/</span>path</pre></td></tr></table></div>

<p>* 192.168.0.6 is IP of remote server.</p>
<p>After you ran this, access to /mount/to/your/local/directory/path directory is same as access to remote directory.</p>
<p>Have fun. <img src='http://www.fengcool.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<a rel="external nofollow" class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.fengcool.com%2F2010%2F10%2Fopen-and-edit-files-from-remote-server%2F&amp;linkname=Open%20and%20edit%20files%20from%20remote%20server"><img src="http://www.fengcool.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Save/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.fengcool.com/2010/10/open-and-edit-files-from-remote-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Remove svn directories and files</title>
		<link>http://www.fengcool.com/2010/10/remove-svn-directories-and-files/</link>
		<comments>http://www.fengcool.com/2010/10/remove-svn-directories-and-files/#comments</comments>
		<pubDate>Tue, 19 Oct 2010 13:57:23 +0000</pubDate>
		<dc:creator>rick</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.fengcool.com/?p=165</guid>
		<description><![CDATA[Deleting all SVN files and directories is a headache if your project contains lots of directories. 
Here is a easy way to delete them with one command.

1
find /path/to/your/directory -type d -name .svn -exec rm -rf '{}' +

]]></description>
			<content:encoded><![CDATA[<p>Deleting all SVN files and directories is a headache if your project contains lots of directories. </p>
<p>Here is a easy way to delete them with one command.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">find</span> <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>your<span style="color: #000000; font-weight: bold;">/</span>directory <span style="color: #660033;">-type</span> d <span style="color: #660033;">-name</span> .svn <span style="color: #660033;">-exec</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #ff0000;">'{}'</span> +</pre></td></tr></table></div>

<a rel="external nofollow" class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.fengcool.com%2F2010%2F10%2Fremove-svn-directories-and-files%2F&amp;linkname=Remove%20svn%20directories%20and%20files"><img src="http://www.fengcool.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Save/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.fengcool.com/2010/10/remove-svn-directories-and-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP file_get_contents connection timeout</title>
		<link>http://www.fengcool.com/2010/04/php-file_get_contents-connection-timeout/</link>
		<comments>http://www.fengcool.com/2010/04/php-file_get_contents-connection-timeout/#comments</comments>
		<pubDate>Tue, 20 Apr 2010 13:30:00 +0000</pubDate>
		<dc:creator>rick</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.fengcool.com/?p=158</guid>
		<description><![CDATA[
1
2
3
4
5
6
7
8
9
&#160;
$context = stream_context_create&#40;array&#40;
    'http' =&#62; array&#40;
        'timeout' =&#62; 60   //timeout after 60 seconds
        &#41;
    &#41;
&#41;; 
&#160;
$file_content = file_get_contents&#40;$source_url,0,$ctx&#41;;

for more stream context options, please visit php.net
]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000088;">$context</span> <span style="color: #339933;">=</span> <span style="color: #990000;">stream_context_create</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'http'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'timeout'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">60</span>   <span style="color: #666666; font-style: italic;">//timeout after 60 seconds</span>
        <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #000088;">$file_content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$source_url</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #000088;">$ctx</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>for more stream context options, please visit <a href='http://ca.php.net/manual/en/function.stream-context-create.php'>php.net</a></p>
<a rel="external nofollow" class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.fengcool.com%2F2010%2F04%2Fphp-file_get_contents-connection-timeout%2F&amp;linkname=PHP%20file_get_contents%20connection%20timeout"><img src="http://www.fengcool.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Save/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.fengcool.com/2010/04/php-file_get_contents-connection-timeout/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP is holiday class</title>
		<link>http://www.fengcool.com/2010/01/php-is-holiday-class/</link>
		<comments>http://www.fengcool.com/2010/01/php-is-holiday-class/#comments</comments>
		<pubDate>Wed, 20 Jan 2010 04:37:01 +0000</pubDate>
		<dc:creator>rick</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[holiday]]></category>

		<guid isPermaLink="false">http://www.fengcool.com/?p=153</guid>
		<description><![CDATA[Test out is it a holiday for any given date. This class currently support United States and Canada's holidays.]]></description>
			<content:encoded><![CDATA[<p>Test out is it a holiday for any given date.</p>
<p>This class currently support United States and Canada&#8217;s holidays.</p>
<p>Here is<br />
<a href="http://en.wikipedia.org/wiki/Public_holidays_in_the_United_States">United States holidays</a> information.<br />
<a href='http://en.wikipedia.org/wiki/Canadian_holidays'>Canadian Holidays</a> information.</p>
<p>This PHP class supports different provinces have its own provincial holidays. For example, December 26th is statutory holiday for Ontario and New Brunswick in Canada.</p>
<p>Usage:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">include_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;IsHoliday.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$h</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Holiday<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'US'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$h</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">is_holiday</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'2010-07-04'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> 
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;yes, 2010-07-04 is holiday in US &lt;br&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">else</span>	
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;no &lt;br&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">//Using Canadian province code for specific province</span>
<span style="color: #000088;">$h</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Holiday<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Canada'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'ON'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$h</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">is_holiday</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'2010-12-26'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> 
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;yes, 2010-12-26 is holiday in Canada &lt;br&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">else</span>	
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;no &lt;br&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><a href='/demo/isHoliday/php-isHoliday.rar'>Download source code here</a></p>
<a rel="external nofollow" class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.fengcool.com%2F2010%2F01%2Fphp-is-holiday-class%2F&amp;linkname=PHP%20is%20holiday%20class"><img src="http://www.fengcool.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Save/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.fengcool.com/2010/01/php-is-holiday-class/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>cp file always getting overwrite prompt?</title>
		<link>http://www.fengcool.com/2009/11/cp-file-always-getting-overwrite-prompt/</link>
		<comments>http://www.fengcool.com/2009/11/cp-file-always-getting-overwrite-prompt/#comments</comments>
		<pubDate>Thu, 26 Nov 2009 05:32:09 +0000</pubDate>
		<dc:creator>rick</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[cp]]></category>
		<category><![CDATA[prompt]]></category>

		<guid isPermaLink="false">http://www.fengcool.com/?p=133</guid>
		<description><![CDATA[linux cp cannot remove overwrite prompt. force no prompt when copy a file.]]></description>
			<content:encoded><![CDATA[<p>wondering why always getting overwrite prompt when use &#8220;cp&#8221; command with &#8220;-f&#8221; option</p>
<p>try this,</p>
<p>1. login as root</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">vi</span> <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>.bashrc</pre></td></tr></table></div>

<p>2. comment out this line</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#alias cp='cp -i'</span></pre></td></tr></table></div>

<p>3. logout and login again</p>
<a rel="external nofollow" class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.fengcool.com%2F2009%2F11%2Fcp-file-always-getting-overwrite-prompt%2F&amp;linkname=cp%20file%20always%20getting%20overwrite%20prompt%3F"><img src="http://www.fengcool.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Save/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.fengcool.com/2009/11/cp-file-always-getting-overwrite-prompt/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Make a copy of mysql table</title>
		<link>http://www.fengcool.com/2009/10/make-copy-mysql-table/</link>
		<comments>http://www.fengcool.com/2009/10/make-copy-mysql-table/#comments</comments>
		<pubDate>Thu, 22 Oct 2009 01:55:23 +0000</pubDate>
		<dc:creator>rick</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[copy table]]></category>

		<guid isPermaLink="false">http://www.fengcool.com/?p=132</guid>
		<description><![CDATA[copy mysql table]]></description>
			<content:encoded><![CDATA[<p>One SQL to make a copy of existing MySQL table ( table structure and records )</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">TABLE</span> clone_table <span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> original_table <span style="color: #990099; font-weight: bold;">WHERE</span> <span style="color: #008080;">1</span></pre></td></tr></table></div>

<a rel="external nofollow" class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.fengcool.com%2F2009%2F10%2Fmake-copy-mysql-table%2F&amp;linkname=Make%20a%20copy%20of%20mysql%20table"><img src="http://www.fengcool.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Save/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.fengcool.com/2009/10/make-copy-mysql-table/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rsync server and client &#8211; backup your server files</title>
		<link>http://www.fengcool.com/2009/07/rsync_server_and_client_backup_server_file/</link>
		<comments>http://www.fengcool.com/2009/07/rsync_server_and_client_backup_server_file/#comments</comments>
		<pubDate>Thu, 30 Jul 2009 17:28:53 +0000</pubDate>
		<dc:creator>rick</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[rsync]]></category>
		<category><![CDATA[rsync client]]></category>
		<category><![CDATA[rsync server]]></category>

		<guid isPermaLink="false">http://www.fengcool.com/?p=112</guid>
		<description><![CDATA[rsync can synchronizes files and directories from one server to another. It's perfectly for backup or create a mirror site purpose.]]></description>
			<content:encoded><![CDATA[<p>rsync can synchronizes files and directories from one server to another. It&#8217;s perfectly for backup or create a mirror site purpose.</p>
<p>This tutorial shows you step by step to create a rsync server and client server.</p>
<p>First of all, you must have rsync installed. For fedora, rsync should be included by default. If you don&#8217;t have it, run</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">yum <span style="color: #c20cb9; font-weight: bold;">install</span> rsync</pre></td></tr></table></div>

<p><strong>Setup rsync server</strong></p>
<p>Create rsync configuration file:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>etc
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> rsyncd
<span style="color: #7a0874; font-weight: bold;">cd</span> rsyncd
<span style="color: #c20cb9; font-weight: bold;">touch</span> rsyncd.conf
<span style="color: #c20cb9; font-weight: bold;">touch</span> rsyncd.motd
<span style="color: #c20cb9; font-weight: bold;">touch</span> rsyncd.user
<span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">600</span> rsyncd.user</pre></td></tr></table></div>

<p>edit rsyncd.user file and create username and password:<br />
vi /etc/rsyncd/rsyncd.user</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">my_rsync_user_1:user_1_password</pre></td></tr></table></div>

<p>edit rsyncd.conf file:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">pid <span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">file</span></span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>rsyncd.pid
<span style="color: #007800;">port</span>=<span style="color: #000000;">873</span>
<span style="color: #007800;">uid</span>=root
<span style="color: #007800;">gid</span>=root
use <span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">chroot</span></span>=<span style="color: #c20cb9; font-weight: bold;">yes</span>
<span style="color: #c20cb9; font-weight: bold;">read</span> <span style="color: #007800;">only</span>=<span style="color: #c20cb9; font-weight: bold;">yes</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># limit access to LANS</span>
hosts <span style="color: #007800;">allow</span>=192.168.2.0<span style="color: #000000; font-weight: bold;">/</span>255.255.255.0   <span style="color: #666666; font-style: italic;">#default, listen to lan server</span>
host <span style="color: #007800;">deny</span>=<span style="color: #000000; font-weight: bold;">*</span>
&nbsp;
max <span style="color: #007800;">connections</span>=<span style="color: #000000;">5</span>
motd <span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">file</span></span>=<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>rsyncd<span style="color: #000000; font-weight: bold;">/</span>rsyncd.motd
&nbsp;
log <span style="color: #007800;">format</span>=<span style="color: #000000; font-weight: bold;">%</span>t<span style="color: #000000; font-weight: bold;">%</span>a<span style="color: #000000; font-weight: bold;">%</span>m<span style="color: #000000; font-weight: bold;">%</span>f<span style="color: #000000; font-weight: bold;">%</span>b
syslog <span style="color: #007800;">facility</span>=local3
<span style="color: #007800;">timeout</span>=<span style="color: #000000;">300</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span>profile_1<span style="color: #7a0874; font-weight: bold;">&#93;</span>          <span style="color: #666666; font-style: italic;">#profile name</span>
path = <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>directory
ignore errors
<span style="color: #c20cb9; font-weight: bold;">read</span> only = <span style="color: #c20cb9; font-weight: bold;">false</span>
list = <span style="color: #c20cb9; font-weight: bold;">false</span>
hosts allow = 66.66.66.66   <span style="color: #666666; font-style: italic;">#listen to client server which use public ip</span>
hosts deny = 0.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">32</span>
auth <span style="color: #c20cb9; font-weight: bold;">users</span> = my_rsync_user_1
secrets <span style="color: #c20cb9; font-weight: bold;">file</span> = <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>rsyncd<span style="color: #000000; font-weight: bold;">/</span>rsyncd.user
&nbsp;
<span style="color: #666666; font-style: italic;">#[profile_1]          #another profile name</span>
<span style="color: #666666; font-style: italic;">#path = /path/to/backup/directory/2</span>
<span style="color: #666666; font-style: italic;">#ignore errors</span>
<span style="color: #666666; font-style: italic;">#read only = false</span>
<span style="color: #666666; font-style: italic;">#list = false</span>
<span style="color: #666666; font-style: italic;">#hosts allow = 88.88.88.88   #listen to client server which use public ip</span>
<span style="color: #666666; font-style: italic;">#hosts deny = 0.0.0.0/32</span>
<span style="color: #666666; font-style: italic;">#auth users = my_rsync_user_2</span>
<span style="color: #666666; font-style: italic;">#secrets file = /etc/rsyncd/rsyncd.user</span></pre></td></tr></table></div>

<p>Next, create init start up script<br />
vi /etc/init.d/rsyncd</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Startup script for rsyncd daemon</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># chkconfig: 35 90 10</span>
<span style="color: #666666; font-style: italic;"># description: Server data for sync to other server</span>
<span style="color: #666666; font-style: italic;"># processname rsync</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Source function library</span>
. <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>rc.d<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>functions
&nbsp;
<span style="color: #007800;">prog</span>=rsync
<span style="color: #007800;">conf</span>=<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>rsyncd<span style="color: #000000; font-weight: bold;">/</span>rsyncd.conf
&nbsp;
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
    start<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Starting rsync daemon: &quot;</span>
        daemon <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$prog</span> <span style="color: #660033;">--daemon</span> <span style="color: #660033;">--config</span>=<span style="color: #007800;">$conf</span>
        <span style="color: #007800;">RETVAL</span>=<span style="color: #007800;">$?</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span>
        <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$RETVAL</span> = <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">touch</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lock<span style="color: #000000; font-weight: bold;">/</span>subsys<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$prog</span>
        <span style="color: #000000; font-weight: bold;">;;</span>
    stop<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Shutting down <span style="color: #007800;">$prog</span>: &quot;</span>
        killproc <span style="color: #660033;">-d</span> <span style="color: #000000;">60</span> <span style="color: #007800;">$prog</span>
        <span style="color: #007800;">RETVAL</span>=<span style="color: #007800;">$?</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span>
        <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$RETVAL</span> = <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lock<span style="color: #000000; font-weight: bold;">/</span>subsys<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$prog</span>
        <span style="color: #000000; font-weight: bold;">;;</span>
    status<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        status <span style="color: #007800;">$prog</span>
        <span style="color: #000000; font-weight: bold;">;;</span>
    restart<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        $<span style="color: #000000;">0</span> stop
        $<span style="color: #000000;">0</span> start
        <span style="color: #000000; font-weight: bold;">;;</span>
    <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Usage: $0 {start|stop|restart|status}&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">esac</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span></pre></td></tr></table></div>

<p>make /etc/init.d/rsyncd executable, and register this service</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>3
4
5
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chmod</span> +x <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>rsyncd 
<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>chkconfig <span style="color: #660033;">--add</span> rsyncd
<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>service rsyncd start</pre></td></tr></table></div>

<p><strong>Setup rsync client</strong></p>
<p>first, of course you must have rsync installed on client server</p>
<p>make rsync password file</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>etc
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> rsync
<span style="color: #7a0874; font-weight: bold;">cd</span> rsync
<span style="color: #c20cb9; font-weight: bold;">touch</span> rsync.pwd
<span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">600</span> rsync.pwd</pre></td></tr></table></div>

<p>vi /etc/rsync/rsync.pwd</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">user_1_password</pre></td></tr></table></div>

<p>execute this command to start synchronize file to server</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">rsync <span style="color: #660033;">-vrtLogp</span> <span style="color: #660033;">--progress</span> <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>directory<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>be<span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/*</span> my_rsync_user_1<span style="color: #000000; font-weight: bold;">@</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>SERVER_IP<span style="color: #7a0874; font-weight: bold;">&#93;</span>::profile_1 <span style="color: #660033;">--password-file</span>=<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>rsync<span style="color: #000000; font-weight: bold;">/</span>rsync.pwd</pre></td></tr></table></div>

<p>where [SERVER_IP] is rsync server IP</p>
<a rel="external nofollow" class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.fengcool.com%2F2009%2F07%2Frsync_server_and_client_backup_server_file%2F&amp;linkname=Rsync%20server%20and%20client%20%26%238211%3B%20backup%20your%20server%20files"><img src="http://www.fengcool.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Save/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.fengcool.com/2009/07/rsync_server_and_client_backup_server_file/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Ajax form upload local image file without refresh</title>
		<link>http://www.fengcool.com/2009/06/ajax-form-upload-local-image-file-without-refresh/</link>
		<comments>http://www.fengcool.com/2009/06/ajax-form-upload-local-image-file-without-refresh/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 01:56:15 +0000</pubDate>
		<dc:creator>rick</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[upload file]]></category>

		<guid isPermaLink="false">http://www.fengcool.com/?p=83</guid>
		<description><![CDATA[Using jquery/ajax to upload image files without refresh the page. This ajax enabled page use hidden form and hidden iframe to upload image implicitly. User may add or remove uploaded images.]]></description>
			<content:encoded><![CDATA[<p>The code example below performs following tasks:</p>
<ul>
<li>Upload multiple image files without refresh page.</li>
<li>Control maximum number of image files to be uploaded.</li>
<li>Instantly review uploaded images.</li>
</ul>
<p><a href="/demo/ajax_image_uploading/">See it in action here</a></p>
<p><a href="/demo/ajax_image_uploading/code.rar">Download source code</a></p>
<p>Basic idea: </p>
<p>You have a Form #1 with input element with type &#8220;file&#8221; to let user to select what images to be uploaded. Also, you need a hidden Form #2 and hidden iframe to do the upload action implicitly. When user select a file, the value of input element needed in Form #2. However, for security reason, browsers are not allow us to manipulate the value of input element, therefore directly copy value of input element to another is not the way to achieve our goal. But, how about copy the whole input element to Form #2? Here is the code.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;http://code.jquery.com/jquery-latest.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>script  type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #003366; font-weight: bold;">var</span> frameId <span style="color: #339933;">=</span> <span style="color: #3366CC;">'frame_ID'</span><span style="color: #339933;">;</span>         <span style="color: #006600; font-style: italic;">//hidden frame id</span>
<span style="color: #003366; font-weight: bold;">var</span> jFrame <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>                <span style="color: #006600; font-style: italic;">//hidden frame object</span>
<span style="color: #003366; font-weight: bold;">var</span> formId <span style="color: #339933;">=</span> <span style="color: #3366CC;">'form_ID'</span><span style="color: #339933;">;</span>           <span style="color: #006600; font-style: italic;">//hidden form id</span>
<span style="color: #003366; font-weight: bold;">var</span> jForm <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>                 <span style="color: #006600; font-style: italic;">//hidden form object</span>
<span style="color: #003366; font-weight: bold;">var</span> fileMax <span style="color: #339933;">=</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">;</span>                  <span style="color: #006600; font-style: italic;">//maximum number of file to be uploaded</span>
<span style="color: #003366; font-weight: bold;">var</span> fileCount <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>                <span style="color: #006600; font-style: italic;">//file counter</span>
<span style="color: #003366; font-weight: bold;">var</span> uploadUrl <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;save.php&quot;</span><span style="color: #339933;">;</span>       <span style="color: #006600; font-style: italic;">//where to handle uploaded image</span>
&nbsp;
&nbsp;
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>                     
&nbsp;
jForm <span style="color: #339933;">=</span> createForm<span style="color: #009900;">&#40;</span>formId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>            <span style="color: #006600; font-style: italic;">//create hidden form</span>
jFrame <span style="color: #339933;">=</span> createUploadIframe<span style="color: #009900;">&#40;</span>frameId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #006600; font-style: italic;">//create hidden iframe</span>
&nbsp;
<span style="color: #006600; font-style: italic;">//append hidden form to hidden iframe</span>
jForm.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'body'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>         
jForm.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'target'</span><span style="color: #339933;">,</span>frameId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>          <span style="color: #006600; font-style: italic;">//make form target to iframe</span>
&nbsp;
<span style="color: #006600; font-style: italic;">//bind onchange function to input element</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#inp&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'change'</span><span style="color: #339933;">,</span>startUpload<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> startUpload<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>jForm<span style="color: #339933;">!=</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>               
      jForm.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>                        <span style="color: #006600; font-style: italic;">//re-create hidden form</span>
      jForm <span style="color: #339933;">=</span> createForm<span style="color: #009900;">&#40;</span>formId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      jForm.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'body'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      jForm.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'target'</span><span style="color: #339933;">,</span>frameId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #003366; font-weight: bold;">var</span> newElement <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">clone</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   <span style="color: #006600; font-style: italic;">//clone input element object</span>
   newElement.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'change'</span><span style="color: #339933;">,</span>startUpload<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #006600; font-style: italic;">//bind onchange function. detect iframe changes</span>
   newElement.<span style="color: #660066;">insertAfter</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>        <span style="color: #006600; font-style: italic;">//insert clone object to current input element object</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span>jForm<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>                   
&nbsp;
   jForm.<span style="color: #660066;">submit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>                         <span style="color: #006600; font-style: italic;">//let's upload the file</span>
&nbsp;
   jFrame.<span style="color: #660066;">unbind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'load'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>                  
   jFrame.<span style="color: #660066;">load</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>        <span style="color: #006600; font-style: italic;">//bind onload function to hidden iframe</span>
&nbsp;
      <span style="color: #006600; font-style: italic;">//get response message from hidden iframe</span>
      <span style="color: #003366; font-weight: bold;">var</span> myFrame <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'name'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   
      <span style="color: #003366; font-weight: bold;">var</span> response <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>myFrame.<span style="color: #660066;">contentWindow</span>.<span style="color: #660066;">document</span>.<span style="color: #660066;">body</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #006600; font-style: italic;">/*
      * you may handle upload status from reponse message.
      * in this example, upload succeeded if message contains &quot;.gif&quot; , otherwise, alert reponse message
      */</span>
&nbsp;
      <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>response.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.gif'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">!=-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">//upload successfully</span>
&nbsp;
         <span style="color: #006600; font-style: italic;">//show thumbnails, add text box with file name</span>
         addUpload<span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">floor</span><span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">random</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #CC0000;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>response<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   
         fileCount<span style="color: #339933;">++;</span>
         <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>fileCount <span style="color: #339933;">&gt;=</span> fileMax<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>   <span style="color: #006600; font-style: italic;">//reach maximum upload file, disable input element</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#inp&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'disabled'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'disable'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>  <span style="color: #006600; font-style: italic;">//error</span>
         <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> createUploadIframe<span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   <span style="color: #006600; font-style: italic;">//set top and left to make form invisible</span>
   <span style="color: #000066; font-weight: bold;">return</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;iframe width=&quot;300&quot; height=&quot;200&quot; name=&quot;'</span> <span style="color: #339933;">+</span> id <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot; id=&quot;'</span> <span style="color: #339933;">+</span> id <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot;&gt;&lt;/iframe&gt;'</span><span style="color: #009900;">&#41;</span>
         .<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>position<span style="color: #339933;">:</span> <span style="color: #3366CC;">'absolute'</span><span style="color: #339933;">,</span>top<span style="color: #339933;">:</span> <span style="color: #3366CC;">'270px'</span><span style="color: #339933;">,</span>left<span style="color: #339933;">:</span> <span style="color: #3366CC;">'450px'</span><span style="color: #339933;">,</span>border<span style="color: #339933;">:</span><span style="color: #3366CC;">'1px solid #f00'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
         .<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'body'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> createForm<span style="color: #009900;">&#40;</span>formId<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000066; font-weight: bold;">return</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;form method=&quot;post&quot; action=&quot;'</span><span style="color: #339933;">+</span>uploadUrl<span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot; name=&quot;'</span> <span style="color: #339933;">+</span> formId <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot; id=&quot;'</span> <span style="color: #339933;">+</span> formId <span style="color: #339933;">+</span> 
            <span style="color: #3366CC;">'&quot; enctype=&quot;multipart/form-data&quot; style=&quot;position:absolute;border:1px solid #f00;'</span><span style="color: #339933;">+</span>
            <span style="color: #3366CC;">'width:300px;height:100px;left:450px;top:150px;padding:5px&quot;&gt;'</span> <span style="color: #339933;">+</span>
            <span style="color: #3366CC;">'&lt;strong&gt;You should hide red blocks&lt;/strong&gt;&lt;br&gt;&lt;br&gt;&lt;/form&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> addUpload<span style="color: #009900;">&#40;</span>id<span style="color: #339933;">,</span>img<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   <span style="color: #003366; font-weight: bold;">var</span> div <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'id'</span><span style="color: #339933;">,</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #006600; font-style: italic;">//add uploaded image</span>
   div.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;img src='&quot;</span><span style="color: #339933;">+</span>img<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;'&gt;&lt;br /&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #006600; font-style: italic;">//add text box</span>
   <span style="color: #003366; font-weight: bold;">var</span> fileName <span style="color: #339933;">=</span> img.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span>img.<span style="color: #660066;">lastIndexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;/&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #003366; font-weight: bold;">var</span> txtbx <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'name'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'img[]'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'type'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'text'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>fileName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009966; font-style: italic;">/* you may want to change textbox to a hidden field in production */</span>
   <span style="color: #006600; font-style: italic;">//var txtbx = $(document.createElement('input')).attr('name','img[]').attr('type','hidden').val(fileName);</span>
   txtbx.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span>div<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
   <span style="color: #006600; font-style: italic;">//add remove thumbnail link</span>
   <span style="color: #003366; font-weight: bold;">var</span> rem <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                               .<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'alt'</span><span style="color: #339933;">,</span>id<span style="color: #009900;">&#41;</span>
                               .<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'href'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'javascript:;'</span><span style="color: #009900;">&#41;</span>
                               .<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Remove&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span>removeUpload<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>      
   rem.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span>div<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #006600; font-style: italic;">//add to the page</span>
   div.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#uploaded_thumb&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> removeUpload<span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   <span style="color: #003366; font-weight: bold;">var</span> removeId <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">target</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'alt'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#'</span><span style="color: #339933;">+</span>removeId<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>fileCount<span style="color: #339933;">&gt;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> fileCount<span style="color: #339933;">--;</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#inp&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeAttr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'disabled'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>form<span style="color: #339933;">&gt;</span>   
   <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #3366CC;">'uploaded_thumb'</span><span style="color: #339933;">&gt;&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>div style<span style="color: #339933;">=</span><span style="color: #3366CC;">'padding-top:20px'</span><span style="color: #339933;">&gt;</span>
   upload a small GIF <span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #3366CC;">'file'</span> <span style="color: #000066;">name</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'image'</span> id<span style="color: #339933;">=</span><span style="color: #3366CC;">'inp'</span><span style="color: #339933;">&gt;</span>
   <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;/</span>form<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<a rel="external nofollow" class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.fengcool.com%2F2009%2F06%2Fajax-form-upload-local-image-file-without-refresh%2F&amp;linkname=Ajax%20form%20upload%20local%20image%20file%20without%20refresh"><img src="http://www.fengcool.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Save/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.fengcool.com/2009/06/ajax-form-upload-local-image-file-without-refresh/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>Backup newly modified files</title>
		<link>http://www.fengcool.com/2009/02/backup-newly-modified-files/</link>
		<comments>http://www.fengcool.com/2009/02/backup-newly-modified-files/#comments</comments>
		<pubDate>Mon, 02 Feb 2009 03:27:03 +0000</pubDate>
		<dc:creator>rick</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[backup files]]></category>
		<category><![CDATA[modified files]]></category>
		<category><![CDATA[tar]]></category>

		<guid isPermaLink="false">http://www.fengcool.com/?p=70</guid>
		<description><![CDATA[backup new modified files, avoid doing full backup]]></description>
			<content:encoded><![CDATA[<p>My server backups over 20GB files everyday. It takes hours to tar those huge amount of files. I think this kind of stupid task is harmful to hard driver. One more stupid issue is that over 99% of files are not modified since last backup. So, here is the command to let me backup newly modified files only.</p>
<p>tar -zcvf /save/to/file.tar /filePath/*  &#8211;newer-mtime &#8216;1 days ago&#8217;</p>
<p>You may want to change &#8220;1 days ago&#8221; to 2 days, or 5 days.</p>
<p>By the way, it&#8217;s better to do full backup monthly or bi-monthly.  <img src='http://www.fengcool.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<a rel="external nofollow" class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.fengcool.com%2F2009%2F02%2Fbackup-newly-modified-files%2F&amp;linkname=Backup%20newly%20modified%20files"><img src="http://www.fengcool.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Save/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.fengcool.com/2009/02/backup-newly-modified-files/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

