<?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"
	>

<channel>
	<title>Moki Systems Blog</title>
	<atom:link href="http://www.mokisystems.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mokisystems.com/blog</link>
	<description>Addressing such topics as: web programming, design, ruby on rails, cake php, postgresql, linux, seo</description>
	<pubDate>Wed, 23 Jul 2008 16:30:15 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<item>
		<title>Ajax multi file upload with php, iframe, &#038; javascript</title>
		<link>http://www.mokisystems.com/blog/ajax-multi-file-upload-with-php-iframe-javascript/</link>
		<comments>http://www.mokisystems.com/blog/ajax-multi-file-upload-with-php-iframe-javascript/#comments</comments>
		<pubDate>Tue, 22 Jul 2008 22:08:35 +0000</pubDate>
		<dc:creator>andrew</dc:creator>
		
		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[ajax]]></category>

		<category><![CDATA[javaxcript]]></category>

		<category><![CDATA[multi-file upload]]></category>

		<guid isPermaLink="false">http://www.mokisystems.com/blog/?p=28</guid>
		<description><![CDATA[I found several solutions after browsing around google trying to find a multi-file uploader built around php.  Most of these solutions for multi-file uploading fit into one of these three categories.

Use Flash to upload the images.  (The browser only supports one image at a time) - SWFUpload
Use Javascript to add multiple file type [...]]]></description>
			<content:encoded><![CDATA[<p>I found several solutions after browsing around google trying to find a multi-file uploader built around php.  Most of these solutions for multi-file uploading fit into one of these three categories.</p>
<ol>
<li>Use Flash to upload the images.  (The browser only supports one image at a time) - <a href="http://swfupload.org/">SWFUpload</a></li>
<li>Use Javascript to add multiple file type fields, while hidding previous fields - <a href="http://the-stickman.com/web-development/javascript/multiple-file-uploader-mootools-version/">the-stickman</a></li>
<li>Use Javascript and hidden iframes embedded on the same page to upload the images. - <a href="http://www.ajaxf1.com/tutorial/ajax-file-upload-tutorial.html">ajaxf1</a></li>
</ol>
<p>I decided to take pieces of the mentioned methods and come up with a solution that worked for me.</p>
<p>Here is the idea behind what we are going to be doing.</p>
<ol>
<li>Create a HTML form which has a file upload field</li>
<li>Set the target of this HTML form to an iFrame which is on the same page</li>
<li>Have Javascript submit the form everytime the &#8220;file&#8221; field changes</li>
<li>Javascript hides the form when submitted, and displays an &#8220;animation&#8221;</li>
<li>PHP takes the uploaded file, thumbnails it, and stores the image data</li>
<li>Javascript unhides the form, and re-hides the animation when upload is complete</li>
<li>Javascript and php show the thumbnail on the same page right after it was uploaded</li>
</ol>
<p>This makes this little script appear like an ajax application.  It is NOT actually AJAX, but uses css, iframes, php sessions, and javascript to make it appear so.</p>
<p>I&#8217;ll try to explain what is happening at each step, but keep in mind, I&#8217;m not an expert programmer like my fellow co-workers, and I borrowed most of the work from the mentioned sources above.  If you just want to download all the files and take the easy way out, skip to the bottom of the post.</p>
<p><strong>Steps 1 &#038; 2 &#038; 3 - Make Our Form</strong></p>

<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="javascript"><span style="color: #339933;">&lt;</span>form <span style="color: #000066;">name</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;pictureform&quot;</span> action<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;upload.php&quot;</span> method<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;post&quot;</span> enctype<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;multipart/form-data&quot;</span> target<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;upload_target&quot;</span> <span style="color: #339933;">&gt;</span>
     <span style="color: #339933;">&lt;</span>p id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;f1_upload_process&quot;</span><span style="color: #339933;">&gt;</span>Loading...<span style="color: #339933;">&lt;</span>br<span style="color: #339933;">/&gt;&lt;</span>img src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;loader.gif&quot;</span> <span style="color: #339933;">/&gt;&lt;</span>br<span style="color: #339933;">/&gt;&lt;/</span>p<span style="color: #339933;">&gt;</span>
     <span style="color: #339933;">&lt;</span>p id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;f1_upload_form&quot;</span> align<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;center&quot;</span><span style="color: #339933;">&gt;&lt;</span>br<span style="color: #339933;">/&gt;</span>
         <span style="color: #339933;">&lt;</span>label<span style="color: #339933;">&gt;</span>Add Pictures<span style="color: #339933;">:</span>  
              <span style="color: #339933;">&lt;</span>input <span style="color: #000066;">name</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;myfile&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;file&quot;</span> size<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;30&quot;</span> onchange<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;startUpload();document.pictureform.submit();&quot;</span> <span style="color: #339933;">/&gt;</span>
         <span style="color: #339933;">&lt;/</span>label<span style="color: #339933;">&gt;</span>					 
     <span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
     <span style="color: #339933;">&lt;</span>iframe id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;upload_target&quot;</span> <span style="color: #000066;">name</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;upload_target&quot;</span> src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;#&quot;</span> style<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;width:0;height:0;border:0px solid #fff;&quot;</span><span style="color: #339933;">&gt;&lt;/</span>iframe<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>form<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p><span id="more-28"></span><br />
Explanation of the mentioned code:<br />
<code>enctype="multipart/form-data"</code><br />
Tells the browser you are submitting files, or images with your form.</p>
<p><code>onchange="startUpload();document.pictureform.submit();</code><br />
The onchange event of the input field calls the function startUpload(), which will hide the form, and show the animation while uploading.  The document.pictureform.submit(); Submits the form to our &#8220;action&#8221; which we have as &#8220;upload.php&#8221;</p>
<p><strong>Step 4 - Make the JavaScript functions for hiding and showing</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="javascript"><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>
      document.<span style="color: #006600;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'f1_upload_process'</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">style</span>.<span style="color: #006600;">visibility</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'visible'</span><span style="color: #339933;">;</span>
      document.<span style="color: #006600;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'f1_upload_form'</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">style</span>.<span style="color: #006600;">visibility</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'hidden'</span><span style="color: #339933;">;</span>
      <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Explanation of the mentioned code:<br />
By giving our HTML elements id tags,such as <code>id=f1_upload_process</code><br />
we make them available for manipulation by JavaScript via the DOM.</p>
<p><code>document.getElementById('f1_upload_process').style.visibility = 'visible';</code><br />
says: &#8220;get the element in the document that has an id of &#8220;f1_upload_process&#8221; and make it visible.&#8221;</p>
<p>This then turns on the visibility of our &#8220;animation&#8221;
<p> block which we have set &#8220;invisible&#8221; by default in our CSS file.  The opposite occurs for the form block, we make it &#8220;invisible&#8221; or &#8220;hidden.&#8221;</p>
<p>Step 5 - Create our &#8220;upload.php&#8221; script to handle thumbnail and copy image to filesystem</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
</pre></td><td class="code"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #666666; font-style: italic;">// keep our session</span>
	<span style="color: #990000;">session_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Check the upload file type</span>
&nbsp;
	<span style="color: #000033;">$filetype</span> <span style="color: #339933;">=</span> <span style="color: #000033;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'myfile'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'type'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000033;">$gd_function_suffix</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>  
 		<span style="color: #0000ff;">'image/pjpeg'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'JPEG'</span><span style="color: #339933;">,</span> 
 		<span style="color: #0000ff;">'image/jpeg'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'JPEG'</span><span style="color: #339933;">,</span> 
 		<span style="color: #0000ff;">'image/gif'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'GIF'</span><span style="color: #339933;">,</span> 
 		<span style="color: #0000ff;">'image/bmp'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'WBMP'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'image/png'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'PNG'</span><span style="color: #339933;">,</span>
 		<span style="color: #0000ff;">'image/x-png'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'PNG'</span> 
		<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000033;">$function_suffix</span> <span style="color: #339933;">=</span> <span style="color: #000033;">$gd_function_suffix</span><span style="color: #009900;">&#91;</span><span style="color: #000033;">$filetype</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Build Function name for ImageCreateFromSUFFIX </span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000033;">$function_suffix</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000033;">$err</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Unsupported file type, must be JPG|PNG|GIF|BMP&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000033;">$function_to_read</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'ImageCreateFrom'</span> <span style="color: #339933;">.</span> <span style="color: #000033;">$function_suffix</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Get the image and create a thumbnail</span>
	<span style="color: #000033;">$img</span> <span style="color: #339933;">=</span> <span style="color: #000033;">$function_to_read</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'myfile'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tmp_name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000033;">$img</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000033;">$err</span> <span style="color: #339933;">=</span>  <span style="color: #0000ff;">&quot;could not create image handle&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000033;">$width</span> <span style="color: #339933;">=</span> imageSX<span style="color: #009900;">&#40;</span><span style="color: #000033;">$img</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// Get the image width</span>
	<span style="color: #000033;">$height</span> <span style="color: #339933;">=</span> imageSY<span style="color: #009900;">&#40;</span><span style="color: #000033;">$img</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Get the image height</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000033;">$width</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span><span style="color: #000033;">$height</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000033;">$err</span> <span style="color: #339933;">=</span>  <span style="color: #0000ff;">&quot;No Width or Height&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Build the thumbnail</span>
	<span style="color: #000033;">$target_width</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// Thumnail width</span>
	<span style="color: #000033;">$target_height</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Thumbnail height</span>
	<span style="color: #000033;">$target_ratio</span> <span style="color: #339933;">=</span> <span style="color: #000033;">$target_width</span> <span style="color: #339933;">/</span> <span style="color: #000033;">$target_height</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">//New target ratio</span>
&nbsp;
	<span style="color: #000033;">$img_ratio</span> <span style="color: #339933;">=</span> <span style="color: #000033;">$width</span> <span style="color: #339933;">/</span> <span style="color: #000033;">$height</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// Original ratio</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000033;">$target_ratio</span> <span style="color: #339933;">&gt;</span> <span style="color: #000033;">$img_ratio</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000033;">$new_height</span> <span style="color: #339933;">=</span> <span style="color: #000033;">$target_height</span><span style="color: #339933;">;</span>
		<span style="color: #000033;">$new_width</span> <span style="color: #339933;">=</span> <span style="color: #000033;">$img_ratio</span> <span style="color: #339933;">*</span> <span style="color: #000033;">$target_height</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Tall Image</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000033;">$new_height</span> <span style="color: #339933;">=</span> <span style="color: #000033;">$target_width</span> <span style="color: #339933;">/</span> <span style="color: #000033;">$img_ratio</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Wide Image</span>
		<span style="color: #000033;">$new_width</span> <span style="color: #339933;">=</span> <span style="color: #000033;">$target_width</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000033;">$new_height</span> <span style="color: #339933;">&gt;</span> <span style="color: #000033;">$target_height</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000033;">$new_height</span> <span style="color: #339933;">=</span> <span style="color: #000033;">$target_height</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000033;">$new_width</span> <span style="color: #339933;">&gt;</span> <span style="color: #000033;">$target_width</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000033;">$new_height</span> <span style="color: #339933;">=</span> <span style="color: #000033;">$target_width</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000033;">$new_img</span> <span style="color: #339933;">=</span> ImageCreateTrueColor<span style="color: #009900;">&#40;</span><span style="color: #000033;">$target_width</span><span style="color: #339933;">,</span> <span style="color: #000033;">$target_height</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Create a new image handle for thumbnail</span>
	<span style="color: #000033;">$white</span> <span style="color: #339933;">=</span> imagecolorallocate<span style="color: #009900;">&#40;</span><span style="color: #000033;">$new_img</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Allocate the color white</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!@</span>imagefilledrectangle<span style="color: #009900;">&#40;</span><span style="color: #000033;">$new_img</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000033;">$target_width</span><span style="color: #cc66cc;">-1</span><span style="color: #339933;">,</span> <span style="color: #000033;">$target_height</span><span style="color: #cc66cc;">-1</span><span style="color: #339933;">,</span> <span style="color: #000033;">$white</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>	<span style="color: #666666; font-style: italic;">// Fill the image white</span>
		<span style="color: #000033;">$err</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Couldn't fill image&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #666666; font-style: italic;">// Copy the uploaded image to the newly created image</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!@</span>imagecopyresampled<span style="color: #009900;">&#40;</span><span style="color: #000033;">$new_img</span><span style="color: #339933;">,</span> <span style="color: #000033;">$img</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #000033;">$target_width</span><span style="color: #339933;">-</span><span style="color: #000033;">$new_width</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #000033;">$target_height</span><span style="color: #339933;">-</span><span style="color: #000033;">$new_height</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000033;">$new_width</span><span style="color: #339933;">,</span> <span style="color: #000033;">$new_height</span><span style="color: #339933;">,</span> <span style="color: #000033;">$width</span><span style="color: #339933;">,</span> <span style="color: #000033;">$height</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000033;">$err</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;couldn't copy new image&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Create php Session array for image information</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;file_info&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000033;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;file_info&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Use a output buffering to load the image into a variable</span>
	<span style="color: #990000;">ob_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	imagejpeg<span style="color: #009900;">&#40;</span><span style="color: #000033;">$new_img</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000033;">$imagevariable</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ob_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">ob_end_clean</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Create a unique id or name for the image</span>
	<span style="color: #000033;">$file_id</span> <span style="color: #339933;">=</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;myfile&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;tmp_name&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">100000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000033;">$new_name</span> <span style="color: #339933;">=</span> <span style="color: #000033;">$file_id</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;.$function_suffix&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000033;">$temp_name</span> <span style="color: #339933;">=</span> <span style="color: #000033;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;myfile&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;tmp_name&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// assign upload directory, and target path for image</span>
	<span style="color: #000033;">$uploaddir</span> <span style="color: #339933;">=</span> <span style="color: #990000;">getcwd</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//</span>
	<span style="color: #000033;">$target_path</span> <span style="color: #339933;">=</span> <span style="color: #000033;">$uploaddir</span><span style="color: #339933;">.</span>DIRECTORY_SEPARATOR<span style="color: #339933;">.</span><span style="color: #000033;">$new_name</span><span style="color: #339933;">;</span>
&nbsp;
 	<span style="color: #666666; font-style: italic;">// Move uploaded image to uploaddir location</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!@</span><span style="color: #990000;">move_uploaded_file</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$temp_name</span><span style="color: #339933;">,</span> <span style="color: #000033;">$target_path</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000033;">$err</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Couldn't Copy File to Filesystem&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #666666; font-style: italic;">// Create a Session array with name, type, and image object for use in displaying thumbnails</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;file_info&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000033;">$file_id</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000033;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;file_info&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000033;">$file_id</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>										<span style="color: #0000ff;">&quot;name&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000033;">$new_name</span><span style="color: #339933;">,</span> 								<span style="color: #0000ff;">&quot;type&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000033;">$function_suffix</span><span style="color: #339933;">,</span> 
						<span style="color: #0000ff;">&quot;obj&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000033;">$imagevariable</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: #666666; font-style: italic;">// If no error, then pass good result and file id to Javascript for generating the thumbnail.</span>
   <span style="color: #666666; font-style: italic;">// Pass our $err varialbe along</span>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000033;">$err</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000033;">$result</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;'1','&quot;</span><span style="color: #339933;">.</span><span style="color: #000033;">$file_id</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #339933;">;</span>	
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
	    <span style="color: #000033;">$result</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;'.$err.','&quot;</span><span style="color: #339933;">.</span><span style="color: #000033;">$file_id</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #339933;">;</span>
   	<span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #990000;">sleep</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// in case of really fast upload, sleep script to show loading animation for a bit longer</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Javascript calls the &quot;stopUpload&quot; function with its paramaters</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;script language</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;javascript&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>window<span style="color: #339933;">.</span>top<span style="color: #339933;">.</span>window<span style="color: #339933;">.</span>stopUpload<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> <span style="color: #000033;">$result</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Explanation of Code:<br />
These php functions make use of the GD library.  You must have that enabled in PHP in order to use this.  Also make sure your current directory is writeable.</p>
<p>I won&#8217;t explain to many things here, as the code has inline comments.  You could make this code a function and have it thumbnail and save multiple sizes to the filesytem.  Currently it simply thumbnails a 100  X 100 and copies the original to the current directory the script is running from.  It will do GIF, JPEG, BMP, or PNG.  Error checking and Session handling could be improved.</p>
<p><strong>Step 6 - Create JavaScript function to show form, and hide animation when upload is finished</strong></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
</pre></td><td class="code"><pre class="javascript"><span style="color: #003366; font-weight: bold;">function</span> stopUpload<span style="color: #009900;">&#40;</span>success<span style="color: #339933;">,</span>fileid<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #003366; font-weight: bold;">var</span> result <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
      <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>success <span style="color: #339933;">==</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
         result <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;span class=&quot;msg&quot;&gt;The file was uploaded successfully!&lt;<span style="color: #000099; font-weight: bold;">\/</span>span&gt;&lt;br/&gt;&lt;br/&gt;'</span><span style="color: #339933;">;</span>
		 addImage<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;thumbnail.php?id=&quot;</span> <span style="color: #339933;">+</span> fileid<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
         result <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;span class=&quot;emsg&quot;&gt;There was an error during file upload!'</span> <span style="color: #339933;">+</span> success <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;<span style="color: #000099; font-weight: bold;">\/</span>span&gt;&lt;br/&gt;&lt;br/&gt;'</span><span style="color: #339933;">;</span> 
      <span style="color: #009900;">&#125;</span>
      document.<span style="color: #006600;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'f1_upload_process'</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">style</span>.<span style="color: #006600;">visibility</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'hidden'</span><span style="color: #339933;">;</span>
      document.<span style="color: #006600;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'f1_upload_form'</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">innerHTML</span> <span style="color: #339933;">=</span> result <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;label&gt;File: &lt;input name=&quot;myfile&quot; type=&quot;file&quot; size=&quot;30&quot;  onchange=&quot;startUpload();document.pictureform.submit();&quot; /&gt;&lt;<span style="color: #000099; font-weight: bold;">\/</span>label&gt;'</span><span style="color: #339933;">;</span>
      document.<span style="color: #006600;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'f1_upload_form'</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">style</span>.<span style="color: #006600;">visibility</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'visible'</span><span style="color: #339933;">;</span>      
&nbsp;
	  <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>   
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Explanation of Code:<br />
From our upload.php script, we passed two varialbes to this JavaScript function, Success and File Id.<br />
If we had a successful file upload, we throw up a message saying &#8220;success&#8221; and call another function called <code> addImage("thumbnail.php?id=" + fileid);</code> <- More on this later...</p>
<p>If we didn't have a successful upload, we return a message saying so.</p>
<p>The last few lines of the function hide the "animation" bar, and recreate our form input element so we can upload another image, and do the whole thing over again.  All without leaving the page!</p>
<p><strong>Step 7 - Our Thumbnail.php script and our addImage() Javascript function</strong></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"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #666666; font-style: italic;">// This script accepts an ID and looks in the user's session for stored thumbnail data.</span>
	<span style="color: #666666; font-style: italic;">// It then streams the data to the browser as an image	</span>
<span style="color: #990000;">session_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000033;">$image_id</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;id&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000033;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;id&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// get the id from the URL</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000033;">$image_id</span> <span style="color: #339933;">===</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;file_info&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;file_info&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000033;">$image_id</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
	<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-type: image/jpeg&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span>
	<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Length: &quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;file_info&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000033;">$image_id</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">echo</span> <span style="color: #000033;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;file_info&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000033;">$image_id</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>obj<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Code Explanation:<br />
This bit of code simply gets the image id from the URL and pulls the image thumbnail data we saved into our session in our upload.php script, and outputs the image to the browser.</p>
<p><strong>addImage() Javascript Function</strong></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
</pre></td><td class="code"><pre class="javascript"><span style="color: #003366; font-weight: bold;">function</span> addImage<span style="color: #009900;">&#40;</span>src<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> newImg <span style="color: #339933;">=</span> document.<span style="color: #006600;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;img&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	newImg.<span style="color: #006600;">style</span>.<span style="color: #006600;">margin</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;5px&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	document.<span style="color: #006600;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;thumbnails&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">appendChild</span><span style="color: #009900;">&#40;</span>newImg<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>newImg.<span style="color: #006600;">filters</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			newImg.<span style="color: #006600;">filters</span>.<span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;DXImageTransform.Microsoft.Alpha&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">opacity</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #006600; font-style: italic;">// If it is not set initially, the browser will throw an error.  This will set it if it is not set yet.</span>
			newImg.<span style="color: #006600;">style</span>.<span style="color: #006600;">filter</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'progid:DXImageTransform.Microsoft.Alpha(opacity='</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">0</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">')'</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>
		newImg.<span style="color: #006600;">style</span>.<span style="color: #006600;">opacity</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	newImg.<span style="color: #000066;">onload</span> <span style="color: #339933;">=</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>
		fadeIn<span style="color: #009900;">&#40;</span>newImg<span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
	newImg.<span style="color: #006600;">src</span> <span style="color: #339933;">=</span> src<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> fadeIn<span style="color: #009900;">&#40;</span>element<span style="color: #339933;">,</span> opacity<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> reduceOpacityBy <span style="color: #339933;">=</span> <span style="color: #CC0000;">5</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> rate <span style="color: #339933;">=</span> <span style="color: #CC0000;">30</span><span style="color: #339933;">;</span>	<span style="color: #006600; font-style: italic;">// 15 fps</span>
&nbsp;
&nbsp;
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>opacity <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">100</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		opacity <span style="color: #339933;">+=</span> reduceOpacityBy<span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>opacity <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">100</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			opacity <span style="color: #339933;">=</span> <span style="color: #CC0000;">100</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>element.<span style="color: #006600;">filters</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
				element.<span style="color: #006600;">filters</span>.<span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;DXImageTransform.Microsoft.Alpha&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">opacity</span> <span style="color: #339933;">=</span> opacity<span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #006600; font-style: italic;">// If it is not set initially, the browser will throw an error.  This will set it if it is not set yet.</span>
				element.<span style="color: #006600;">style</span>.<span style="color: #006600;">filter</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'progid:DXImageTransform.Microsoft.Alpha(opacity='</span> <span style="color: #339933;">+</span> opacity <span style="color: #339933;">+</span> <span style="color: #3366CC;">')'</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>
			element.<span style="color: #006600;">style</span>.<span style="color: #006600;">opacity</span> <span style="color: #339933;">=</span> opacity <span style="color: #339933;">/</span> <span style="color: #CC0000;">100</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>opacity <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">100</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		setTimeout<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>
			fadeIn<span style="color: #009900;">&#40;</span>element<span style="color: #339933;">,</span> opacity<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> rate<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Code Explanation:<br />
I borrowed most of this code from the SWFUpload project.  The basic idea is that we create a new image tag via javascript, give it a src of &#8220;thumbnail.php?id=XXXXX&#8221; XXXXX being our image name, and call a &#8220;fadeIn&#8221; function which does just that, fade the image in for a lovely effect.  I have this javascript included in my index.php page via</p>

<div class="wp_syntax"><div class="code"><pre>&lt;script type=&quot;text/javascript&quot; src=&quot;handlers.js&quot;&gt;&lt;/script&gt;</pre></div></div>

<p>Thats it!  Hope you learned as much as I did from this tutorial.</p>
<p><em>Important Notes:</em></p>
<p>-This script does not check file size, or limit the number of files that can be uploaded.<br />
-You will need to add in appropriate error checking on the uploaded files for security.<br />
-You will want to clean out the data from the session when done with the uploading.<br />
-Make sure you have write permission the directory where images are being saved<br />
-You must have GD library installed for this script to work</p>
<p>All the files you need to be up and running are found here -> <a href='http://www.mokisystems.com/blog/wp-content/uploads/2008/07/ajax-file-upload-mokisystems.zip'>ajax-file-upload-mokisystems</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mokisystems.com/blog/ajax-multi-file-upload-with-php-iframe-javascript/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How We&#8217;re Using VMWare Server</title>
		<link>http://www.mokisystems.com/blog/how-were-using-vmware-server/</link>
		<comments>http://www.mokisystems.com/blog/how-were-using-vmware-server/#comments</comments>
		<pubDate>Tue, 15 Jul 2008 18:23:47 +0000</pubDate>
		<dc:creator>mark</dc:creator>
		
		<category><![CDATA[Linux]]></category>

		<category><![CDATA[System Administration]]></category>

		<category><![CDATA[VMWare]]></category>

		<guid isPermaLink="false">http://beta.mokisystems.com/blog/?p=9</guid>
		<description><![CDATA[VMWare releasing a free version of their server virtualization product opened up some possibilities for us. Moki Systems had multiple servers performing a variety of tasks but there were things we didn&#8217;t have. We didn&#8217;t have a split between production and development servers and we didn&#8217;t have good utilization. Low CPU and memory utilization offers [...]]]></description>
			<content:encoded><![CDATA[<p>VMWare releasing a free version of their server virtualization product opened up some possibilities for us. Moki Systems had multiple servers performing a variety of tasks but there were things we didn&#8217;t have. We didn&#8217;t have a split between production and development servers and we didn&#8217;t have good utilization. Low CPU and memory utilization offers a comfort level but it adds costs, especially when you need more servers that cost money, use electricity, and generate heat.</p>
<p>Free VMWare server limits running virtual servers to 4. Our solution was to purchase new servers  equipped with 1 SATA disk for the OS and 4 SCSI disks, 1 for each virtual machine (VM). While VMWare offers an option to write to the disk directly I opted not to do that because the virtual disk files VMWare uses make your VM&#8217;s highly portable and easy to duplicate. Disaster recovery practice becomes far easier when you can easily make a duplicate of your production server.</p>
<p>This architecture&#8217;s utility was brought to light when one of your servers died. We were able to pull the disks containing our production servers, copy the VM&#8217;s to another server, then get those servers running again quickly. There was no need for OS reinstall or recovery from backup and because of this portability downtime was minimized.</p>
<p>I have VMWare server installed on my Windows workstation with a Centos 5 VM running in the background. I use it for some MySQL and PHP stuff so it isn&#8217;t used a whole lot but I hardly know it&#8217;s there. The beauty of this that the Windows guys can have a Linux VM and the Linux guys can have a Windows VM. That can help quite a bit when testing browser compatibility on a website or getting access to a tool not available for your OS of choice.</p>
<p>VMWare server has helped us utilize our server resources better at a very minimal cost. Running 4 servers for the price of one saves us time and money. What else could you ask for?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mokisystems.com/blog/how-were-using-vmware-server/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Ruby Timing Shortcut</title>
		<link>http://www.mokisystems.com/blog/ruby-timing-shortcut/</link>
		<comments>http://www.mokisystems.com/blog/ruby-timing-shortcut/#comments</comments>
		<pubDate>Tue, 10 Jun 2008 21:35:53 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
		
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.mokisystems.com/blog/ruby-timing-shortcut/</guid>
		<description><![CDATA[Recently I was trying to optimize my code a little and needed a quick way to compare the speed of different code snippets. Of course Rails comes with the Benchmark module for doing just that. It is, however, in my opinion a bit clunky for quick tests. Look at all the typing it takes just [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I was trying to optimize my code a little and needed a quick way to compare the speed of different code snippets. Of course Rails comes with the <a href="http://www.ruby-doc.org/stdlib/libdoc/benchmark/rdoc/index.html">Benchmark module</a> for doing just that. It is, however, in my opinion a bit clunky for quick tests. Look at all the typing it takes just to find the average speed of a snippet over 100 iterations:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#CC00FF; font-weight:bold;">Benchmark</span>.<span style="color:#9900CC;">bm</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>x<span style="color:#006600; font-weight:bold;">|</span>
  x.<span style="color:#9900CC;">report</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    <span style="color:#006666;">100</span>.<span style="color:#9900CC;">times</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1</span>...<span style="color:#006666;">1000</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">to_a</span>.<span style="color:#9900CC;">sum</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>So I tossed this into my ~/.irbrc file:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#CC0066; font-weight:bold;">Integer</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> ti<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&amp;</span>block<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#CC00FF; font-weight:bold;">Benchmark</span>.<span style="color:#9900CC;">bm</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>x<span style="color:#006600; font-weight:bold;">|</span>
      x.<span style="color:#9900CC;">report</span> <span style="color:#9966CC; font-weight:bold;">do</span>
        <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">times</span> <span style="color:#9966CC; font-weight:bold;">do</span>
          <span style="color:#9966CC; font-weight:bold;">yield</span>
        <span style="color:#9966CC; font-weight:bold;">end</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>And now I can &#8220;time it&#8221; like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#006600; font-weight:bold;">&gt;&gt;</span> <span style="color:#006666;">100</span>.<span style="color:#9900CC;">ti</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1</span>...<span style="color:#006666;">1000</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">to_a</span>.<span style="color:#9900CC;">sum</span><span style="color:#006600; font-weight:bold;">&#125;</span>
      user     <span style="color:#CC0066; font-weight:bold;">system</span>      total        real
  <span style="color:#006666;">0.540000</span>   <span style="color:#006666;">0.050000</span>   <span style="color:#006666;">0.590000</span> <span style="color:#006600; font-weight:bold;">&#40;</span>  <span style="color:#006666;">0.597664</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span></pre></div></div>

<p>Much nicer!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mokisystems.com/blog/ruby-timing-shortcut/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Fragment caching with Radiant CMS</title>
		<link>http://www.mokisystems.com/blog/fragment-caching-with-radiant-cms/</link>
		<comments>http://www.mokisystems.com/blog/fragment-caching-with-radiant-cms/#comments</comments>
		<pubDate>Tue, 10 Jun 2008 21:29:17 +0000</pubDate>
		<dc:creator>wes</dc:creator>
		
		<category><![CDATA[Radiant]]></category>

		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.mokisystems.com/blog/fragment-caching-with-radiant-cms/</guid>
		<description><![CDATA[We&#8217;re in the process of converting our website to Radiant CMS, and one of the new things on the site is a &#8220;Blog Blurbs&#8221; section at the bottom of every page that lists our latest blog post. Our blog is in Wordpress, so I setup the RSS Reader extension in Radiant to fetch the posts. [...]]]></description>
			<content:encoded><![CDATA[<p>We&#8217;re in the process of converting our website to <a href="http://www.radiantcms.com/">Radiant CMS</a>, and one of the new things on the site is a &#8220;Blog Blurbs&#8221; section at the bottom of every page that lists our latest blog post. Our blog is in Wordpress, so I setup the RSS Reader extension in Radiant to fetch the posts. Everything worked great, except that page loading was noticeably slower. After the page gets cached everything is fine but this is included on every page so going through the site when there were not cached pages was really frustrating. I thought about modifying the RSS Reader extension to cache our blog blurbs, but I figured a more general approach would work better, so I came up with a fragment caching extension. We&#8217;re using it like this:</p>

<div class="wp_syntax"><div class="code"><pre>&lt;r:cache name=&quot;rss_fragment&quot; time=&quot;60&quot;&gt;
  &lt;r:feed:items url=&quot;[feed_url]&quot; limit=&quot;1&quot;&gt;
    &lt;h3&gt;&lt;r:feed:link /&gt;&lt;/h3&gt;
    &lt;p&gt;&lt;r:feed:content max_length=&quot;300&quot; no_html=&quot;true&quot; /&gt;&lt;/p&gt;
  &lt;/r:feed:items&gt;
&lt;/r:cache&gt;</pre></div></div>

<p>The code is at <a href="http://github.com/mokisystems/radiant-fragment-cacher/tree/master">github</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mokisystems.com/blog/fragment-caching-with-radiant-cms/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Postgresql Encoding - UTF8</title>
		<link>http://www.mokisystems.com/blog/postgresql-encoding-utf8/</link>
		<comments>http://www.mokisystems.com/blog/postgresql-encoding-utf8/#comments</comments>
		<pubDate>Mon, 09 Jun 2008 20:10:20 +0000</pubDate>
		<dc:creator>james</dc:creator>
		
		<category><![CDATA[PostgreSQL]]></category>

		<category><![CDATA[changing encoding]]></category>

		<category><![CDATA[encoding]]></category>

		<category><![CDATA[pg_dump]]></category>

		<category><![CDATA[postgres]]></category>

		<category><![CDATA[SQL_ASCII]]></category>

		<category><![CDATA[UTF-8]]></category>

		<category><![CDATA[UTF8]]></category>

		<guid isPermaLink="false">http://www.mokisystems.com/blog/postgresql-encoding-utf8/</guid>
		<description><![CDATA[Over the past many years I have been involved in projects requiring localization into many different languages.  One issue with this is how data is stored in the database.  
As we support and help various customers with Postgresql related database issues, we still find users who are encoding their databases in SQL_ASCII.  [...]]]></description>
			<content:encoded><![CDATA[<p>Over the past many years I have been involved in projects requiring localization into many different languages.  One issue with this is how data is stored in the database.  </p>
<p>As we support and help various customers with Postgresql related database issues, we still find users who are encoding their databases in SQL_ASCII.   Perhaps there is a reason for this, if there is I haven&#8217;t figured it out yet.  </p>
<p>In many cases, this eventually causes them problems and they end up having to switch from SQL_ASCII or some other encoding over to UTF8.  </p>
<p>There may be more, but I know of two different ways of converting the encoding of the database to UTF8.</p>
<p>One way is</p>

<div class="wp_syntax"><div class="code"><pre class="bash">iconv -f iso<span style="color: #000000;">-8859</span><span style="color: #000000;">-1</span> -t utf<span style="color: #000000;">-8</span> dump_file dump_file_recoded</pre></div></div>

<p>The preferred way however is to use the -E option of the pg_dump command like this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash">pg_dump -U postgres -W -E UTF8 -d pg_bench <span style="color: #000000; font-weight: bold;">&gt;</span>pgbench.backup.</pre></div></div>

<p>the -W command forces you to put in a password.</p>
<p>For more details on how to use the pg_dump command, here are the docs:</p>
<p><a href="http://www.postgresql.org/docs/8.3/interactive/app-pg_dump.html">http://www.postgresql.org/docs/8.3/interactive/app-pg_dump.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mokisystems.com/blog/postgresql-encoding-utf8/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Recover a deleted file in Subversion</title>
		<link>http://www.mokisystems.com/blog/recover-a-deleted-file-in-subversion/</link>
		<comments>http://www.mokisystems.com/blog/recover-a-deleted-file-in-subversion/#comments</comments>
		<pubDate>Thu, 29 May 2008 17:40:20 +0000</pubDate>
		<dc:creator>brian</dc:creator>
		
		<category><![CDATA[SVN]]></category>

		<category><![CDATA[Subversion]]></category>

		<guid isPermaLink="false">http://www.mokisystems.com/blog/recover-a-deleted-file-in-subversion/</guid>
		<description><![CDATA[SVN is great for keeping our projects under tight control.  Occasionally, we have the need to get something back that was deleted in a previous revision.  So I can remember how to do it next time, here it is:

$ svn copy -r 1234 url/to/deleted/file path/to/recovered/file

This will copy the file at the revision specified [...]]]></description>
			<content:encoded><![CDATA[<p>SVN is great for keeping our projects under tight control.  Occasionally, we have the need to get something back that was deleted in a previous revision.  So I can remember how to do it next time, here it is:</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ svn copy -r <span style="color: #000000;">1234</span> url<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>deleted<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">file</span> path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>recovered<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">file</span></pre></div></div>

<p>This will copy the file at the revision specified to the new file in the &#8220;restore to path&#8221; part.  You can find the revision by doing an &#8217;svn log &#8211;verbose&#8217; of the directory it was in.  That&#8217;s all there is to it!</p>
<p>My theme seems to be restoring and recovering&#8230; is that a bad thing?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mokisystems.com/blog/recover-a-deleted-file-in-subversion/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Restoring MySQL Databases</title>
		<link>http://www.mokisystems.com/blog/restoring-mysql-databases/</link>
		<comments>http://www.mokisystems.com/blog/restoring-mysql-databases/#comments</comments>
		<pubDate>Wed, 21 May 2008 17:48:50 +0000</pubDate>
		<dc:creator>brian</dc:creator>
		
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.mokisystems.com/blog/restoring-mysql-databases/</guid>
		<description><![CDATA[This is a quick post to possibly save someone some time when they google for restoring mysql data files.  The gist of it is, don&#8217;t try to copy InnoDB files directly into your data directory, it won&#8217;t work.
Background
Sometime back I wiped my development box clean and reinstalled the OS from scratch.  It&#8217;s a [...]]]></description>
			<content:encoded><![CDATA[<p>This is a quick post to possibly save someone some time when they google for restoring mysql data files.  The gist of it is, <em>don&#8217;t try to copy InnoDB files directly into your data directory, it won&#8217;t work.</em></p>
<p><strong>Background</strong></p>
<p>Sometime back I wiped my development box clean and reinstalled the OS from scratch.  It&#8217;s a wonderful feeling to start fresh and get rid of all the old whacky configs and random junk that collects on a filesystem.  Prior to this cleansing, I backed up all the junk I considered save-worthy.  One thing I saved was they MySQL data directory.  Many of the databases were old projects and at the time I didn&#8217;t think I&#8217;d need to look at them anytime soon.  Well, anytime soon arrived yesterday in the form of me really wanting to see how I had implemented a particular feature in an old project.  The database component of that project was essential, so I couldn&#8217;t just glance at the code, I wanted to get it running again with the database backend.</p>
<p><strong>Problem</strong></p>
<p>I probably should have known better, but I decided to just try to shutdown mysql and copy the files directly to my new data directory.  After some permission and user adjusting, that seemed to work&#8230; until I actually tried to access the restored database I needed, which used mostly InnoDB tables.  They were not showing up or working properly.  A quick glance revealed a file I hadn&#8217;t copied which seemed like it *might* be something important:</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ <span style="color: #c20cb9; font-weight: bold;">ls</span> -lh <span style="color: #000000; font-weight: bold;">/</span>Backup<span style="color: #000000; font-weight: bold;">/</span>mysql<span style="color: #000000; font-weight: bold;">/</span>data<span style="color: #000000; font-weight: bold;">/</span>
-rw-rw----    <span style="color: #000000;">1</span> brian  staff   <span style="color: #000000;">1</span>.0G May <span style="color: #000000;">21</span> <span style="color: #000000;">10</span>:<span style="color: #000000;">05</span> ibdata1</pre></div></div>

<p>Yeah, oops.  So InnoDB stores things a bit differently than MyISAM.</p>
<p><strong>Solution</strong></p>
<p>The solution turns out to be simple and is what I should have done in the first place.</p>
<p>First, shutdown the mysql server:</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ mysqladmin -u root -p shutdown</pre></div></div>

<p>Next, startup mysqld with the &#8211;datadir option pointing to your old data directory:</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ mysqld --<span style="color: #007800;">datadir=</span><span style="color: #000000; font-weight: bold;">/</span>Backup<span style="color: #000000; font-weight: bold;">/</span>mysql<span style="color: #000000; font-weight: bold;">/</span>data<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>It may complain about some issue with writing to log files, but that doesn&#8217;t matter for this quick export. </p>
<p>Now just dump your database as you normally would (or should have originally):</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ mysqldump -u root -p database_name <span style="color: #000000; font-weight: bold;">&gt;</span> database_name.sql</pre></div></div>

<p>Lastly, shutdown mysqld again, start mysqld normally and then do the import as usual:</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ mysql -u root -p database_name <span style="color: #000000; font-weight: bold;">&lt;</span> database_name.sql</pre></div></div>

<p>(you&#8217;ll likely need to create the database first)</p>
<p>There you have it - the way to get your old database files restored into your current setup.  There is probably some better easier way to do this, and if someone knows it, clue me in will ya?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mokisystems.com/blog/restoring-mysql-databases/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Setting up Slony on Windows</title>
		<link>http://www.mokisystems.com/blog/setting-up-slony-on-windows/</link>
		<comments>http://www.mokisystems.com/blog/setting-up-slony-on-windows/#comments</comments>
		<pubDate>Tue, 13 May 2008 17:54:05 +0000</pubDate>
		<dc:creator>james</dc:creator>
		
		<category><![CDATA[PostgreSQL]]></category>

		<category><![CDATA[Slony]]></category>

		<category><![CDATA[pgadmin]]></category>

		<category><![CDATA[pgadminIII]]></category>

		<category><![CDATA[postgresql replication]]></category>

		<category><![CDATA[postgresql windows]]></category>

		<category><![CDATA[Slony replication]]></category>

		<category><![CDATA[slony windows.]]></category>

		<category><![CDATA[slony1]]></category>

		<category><![CDATA[slonyI]]></category>

		<guid isPermaLink="false">http://www.mokisystems.com/blog/setting-up-slony-on-windows/</guid>
		<description><![CDATA[This isn&#8217;t intended to be a complete tutorial, but for those of us who have previously only run Slony on Linux, this might be a helpful post.

Install Slony
Configure pgAdmin file/options and set the slony path
G:\Program Files (x86)\PostgreSQL\8.2\share
Create the master db
create the slave db
Initialize the master database.  From the command line
pgbench.exe -U postgres -i pb
copy [...]]]></description>
			<content:encoded><![CDATA[<p>This isn&#8217;t intended to be a complete tutorial, but for those of us who have previously only run Slony on Linux, this might be a helpful post.<br />
<span id="more-12"></span></p>
<p>Install Slony</p>
<p>Configure pgAdmin file/options and set the slony path</p>
<p><code>G:\Program Files (x86)\PostgreSQL\8.2\share</code></p>
<p>Create the master db</p>
<p>create the slave db</p>
<p>Initialize the master database.  From the command line<br />
<code>pgbench.exe -U postgres -i pb</code></p>
<p>copy the master to the slave: from command line</p>
<p><code>pg_dump.exe  -U postgres -h localhost pb |psql =U postgres -h localhost pbslave</code></p>
<p>Add a new cluster on the master<img src="file:///C:/DOCUME%7E1/james/LOCALS%7E1/Temp/moz-screenshot-10.jpg" /></p>
<p><a href="http://www.mokisystems.com/blog/wp-content/uploads/2008/05/add_node_on_slave.bmp" title="add_cluster_on_master"><img src="http://www.mokisystems.com/blog/wp-content/uploads/2008/05/add_node_on_slave.bmp" alt="add_cluster_on_master" /></a></p>
<p>Add a node on the slave db</p>
<p><a href="http://www.mokisystems.com/blog/wp-content/uploads/2008/05/add_node_on_slave1.bmp" title="Add_node_on_slave"><img src="http://www.mokisystems.com/blog/wp-content/uploads/2008/05/add_node_on_slave1.bmp" alt="Add_node_on_slave" /></a></p>
<p style="margin-bottom: 0in">Add a path on both the master to the slave</p>
<p style="margin-bottom: 0in">host=localhost port=5432 dbname=pbslave user=postgres password=a</p>
<p style="margin-bottom: 0in">  <a href="http://www.mokisystems.com/blog/wp-content/uploads/2008/05/add_path_on_master.bmp" title="Add_path_on_master"><img src="http://www.mokisystems.com/blog/wp-content/uploads/2008/05/add_path_on_master.bmp" alt="Add_path_on_master" /></a></p>
<p style="margin-bottom: 0in">Add a path on the slave to the master</p>
<p style="margin-bottom: 0in">host=localhost port=5432 dbname=pb user=postgres password=a</p>
<p style="margin-bottom: 0in"><a href="http://www.mokisystems.com/blog/wp-content/uploads/2008/05/add_path_to_master.bmp" title="add_path_on_slave"><img src="http://www.mokisystems.com/blog/wp-content/uploads/2008/05/add_path_to_master.bmp" alt="add_path_on_slave" /></a></p>
<p style="margin-bottom: 0in">Add a replication set on the master</p>
<p style="margin-bottom: 0in"><a href="http://www.mokisystems.com/blog/wp-content/uploads/2008/05/add_replication_set.bmp" title="add_replication_set"><img src="http://www.mokisystems.com/blog/wp-content/uploads/2008/05/add_replication_set.bmp" alt="add_replication_set" /></a></p>
<p style="margin-bottom: 0in">&nbsp;</p>
<p style="margin-bottom: 0in">Add accounts, branches, tellers</p>
<p style="margin-bottom: 0in"><a href="http://www.mokisystems.com/blog/wp-content/uploads/2008/05/add_accounts.bmp" title="add_accounts"><img src="http://www.mokisystems.com/blog/wp-content/uploads/2008/05/add_accounts.bmp" alt="add_accounts" /></a></p>
<p style="margin-bottom: 0in">From the master Subscribe the slave</p>
<p style="margin-bottom: 0in">from the all tables set, right click subscribe set</p>
<p style="margin-bottom: 0in">&nbsp;</p>
<p style="margin-bottom: 0in">&nbsp;</p>
<p style="margin-bottom: 0in">Slony is configured, now we have to make windows start the engines correctly.</p>
<p style="margin-bottom: 0in">&nbsp;</p>
<p style="margin-bottom: 0in">Create two text files in <a href="file:///C:/slony">c:\slony</a></p>
<p style="margin-bottom: 0in">master.conf and slave.conf which look like this:</p>
<p><code>cluster_name='pgbench'<br />
conn_info='dbname=pgbench user=postgres password=a'<br />
</code></p>
<p style="margin-bottom: 0in">From the command line register the engines</p>
<p><code>slon -addengine slony g:\slony\slave.conf<br />
lon -addengine slony g:\slony\master.conf</code></p>
<p style="margin-bottom: 0in">if this hasn&#8217;t been done register slony as a service</p>
<p><code>slon -regservice slony</code></p>
<p>go to services and start slony</p>
<p>check event log for errors</p>
<p>if there are none then run a test from the master:</p>
<p><code>insert into accounts values (100001, 1, 0, 'test');</code></p>
<p style="margin-bottom: 0in">from the slave</p>
<p><code>select count(*) from accounts;</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mokisystems.com/blog/setting-up-slony-on-windows/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Flash AS3 Loading Fonts</title>
		<link>http://www.mokisystems.com/blog/flash-as3-loading-fonts/</link>
		<comments>http://www.mokisystems.com/blog/flash-as3-loading-fonts/#comments</comments>
		<pubDate>Tue, 13 May 2008 17:23:29 +0000</pubDate>
		<dc:creator>dan</dc:creator>
		
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.mokisystems.com/blog/flash-as3-loading-fonts/</guid>
		<description><![CDATA[Create a Flash AS3 application that loads an external font at runtime&#8230; Sounds easy enough&#8230; But it is a little tricky.  I needed to create a flash app that allowed users to choose  a font from a list and load that into a player.  I wanted to offer several fonts but did [...]]]></description>
			<content:encoded><![CDATA[<p>Create a Flash AS3 application that loads an external font at runtime&#8230; Sounds easy enough&#8230; But it is a little tricky.  I needed to create a flash app that allowed users to choose  a font from a list and load that into a player.  I wanted to offer several fonts but did not want to bloat the load-time with unused fonts.  I could not find much help on this topic&#8230; Luckily I found <a href="http://www.betriebsraum.de/blog/2007/06/22/runtime-font-loading-with-as3-flash-cs3-not-flex/" title="Runtime font loading with AS3 / Flash CS3 (not Flex!)" target="_blank">betriebsraum </a>and with that I was able to hack up something that worked for me.<span id="more-10"></span>So here is what i did:step 1:  Created an external swf with the font I needed.  (I created separate ones for each font I was going to offer.)
<ul>
<li>Created a new Fla and add a font to the library.</li>
<li>In the Library pane(F11), click the options dropdown, and choose &#8216;New Font&#8217;</li>
<li>Select a font, size and style&#8211;size is not important ( arguably)&#8211;however, I believe you will have to create separate fonts for each style you require.  The name is not important really either.</li>
<li>Right click the new font in the Library and select &#8216;Linkage&#8230;&#8217;
<ul>
<li>Check &#8216;Export for ActionScript&#8217; and &#8216;Export in first frame&#8217;.</li>
<li>Give it a Class:&#8211;this name <em>is </em>important and you will need to remember it.  I used &#8216;EFont01&#8242; fig. 1</li>
<li><a href="http://www.mokisystems.com/blog/wp-content/uploads/2008/05/dc-linkage.gif" title="Linking"><img src="http://www.mokisystems.com/blog/wp-content/uploads/2008/05/dc-linkage.gif" alt="Linking" /></a></li>
</ul>
</li>
</ul>
<ul>
<li>Publish the swf as &#8216;/font-Fontname.swf&#8217;.</li>
</ul>
<p>Step 2: Create the Application:
<ul>
<li>Create a new Flash CS3/As3 application set the Document class as &#8216;Main&#8217; and save it as &#8216;/myapp.fla&#8217;</li>
<li> Create a new AS3 script and save it as &#8216;/Main.as&#8217;</li>
</ul>
<p><strong>Main.as</strong></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
</pre></td><td class="code"><pre class="actionscript">package <span style="color: #66cc66;">&#123;</span>
 	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
 	<span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #006600;">*</span>;
 	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">*</span>;
 	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Main <span style="color: #0066CC;">extends</span> Sprite <span style="color: #66cc66;">&#123;</span>
 	 	<span style="color: #000000; font-weight: bold;">var</span> t:<span style="color: #0066CC;">TextField</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">TextField</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
 	 	<span style="color: #000000; font-weight: bold;">var</span> f = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">TextFormat</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
 	 	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
 	 	 	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">font</span> = <span style="color: #000000; font-weight: bold;">new</span> LoadFont<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;font-Zapfino.swf&quot;</span>,<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;EFont01&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
 	 	 	<span style="color: #0066CC;">font</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>LoadFont.<span style="color: #006600;">COMPLETE</span>, successLoadFont<span style="color: #66cc66;">&#41;</span>;
 	 	 	<span style="color: #0066CC;">font</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>LoadFont.<span style="color: #0066CC;">ERROR</span>, failLoadFont<span style="color: #66cc66;">&#41;</span>;
 	  	<span style="color: #66cc66;">&#125;</span>
 	 	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> failLoadFont<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
 	 	 	f.<span style="color: #0066CC;">font</span>=<span style="color: #ff0000;">&quot;Arial&quot;</span>; <span style="color: #808080; font-style: italic;">//default font if load fails.</span>
 	 	 	t.<span style="color: #0066CC;">embedFonts</span> = <span style="color: #000000; font-weight: bold;">false</span>;
 	 	 	post<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
 	 	<span style="color: #66cc66;">&#125;</span>
 	 	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> successLoadFont<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
 	 	 	<span style="color: #000000; font-weight: bold;">var</span> embeddedFonts:<span style="color: #0066CC;">Array</span> = <span style="color: #0066CC;">Font</span>.<span style="color: #006600;">enumerateFonts</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span>;
 	 	 	f.<span style="color: #0066CC;">font</span>=embeddedFonts<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">fontName</span>;
 	 	 	t.<span style="color: #0066CC;">embedFonts</span> = <span style="color: #000000; font-weight: bold;">true</span>;
 	 	 	post<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
 	 	<span style="color: #66cc66;">&#125;</span>
 	 	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> post<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
 	 	 	f.<span style="color: #0066CC;">size</span> = <span style="color: #cc66cc;">36</span>;
 	 	 	t.<span style="color: #006600;">defaultTextFormat</span> = f;
 	 	 	t.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">100</span>;
 	 	 	t.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">100</span>;
 	 	 	t.<span style="color: #0066CC;">background</span> = <span style="color: #000000; font-weight: bold;">true</span>;
 	 	 	t.<span style="color: #0066CC;">autoSize</span> = TextFieldAutoSize.<span style="color: #0066CC;">LEFT</span>;
 	 	 	t.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;We are in loaded Font&quot;</span>;
 	 	 	addChild<span style="color: #66cc66;">&#40;</span>t<span style="color: #66cc66;">&#41;</span>;
 	 	<span style="color: #66cc66;">&#125;</span>
 	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<ul>
<li>Create a new AS3 script and save it as &#8216;/LoadFont.as&#8217;</li>
</ul>
<p><strong> LoadFont.as</strong></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
</pre></td><td class="code"><pre class="actionscript">package <span style="color: #66cc66;">&#123;</span>
 	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">*</span>;
 	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">*</span>;
 	<span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #006600;">*</span>;
 	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">errors</span>.<span style="color: #006600;">*</span>;
 	<span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">system</span>.<span style="color: #006600;">*</span>;
 	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">*</span>;
 	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> LoadFont <span style="color: #0066CC;">extends</span> EventDispatcher <span style="color: #66cc66;">&#123;</span>
 	 	<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const COMPLETE:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;complete&quot;</span>;
 	 	<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const <span style="color: #0066CC;">ERROR</span>:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;error loading font&quot;</span>;
 	 	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> loader:Loader = <span style="color: #000000; font-weight: bold;">new</span> Loader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
 	 	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _fontsDomain:ApplicationDomain;
 	 	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _fontName:<span style="color: #0066CC;">Array</span>;
 	 	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> LoadFont<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">url</span>:<span style="color: #0066CC;">String</span>,fontName:<span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
 	 	 	_fontName = fontName;
 	 	 	<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;loading&quot;</span><span style="color: #66cc66;">&#41;</span>;
 	 	 	loader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>IOErrorEvent.<span style="color: #006600;">IO_ERROR</span>, font_ioErrorHandler<span style="color: #66cc66;">&#41;</span>;
 	 	 	loader.<span style="color: #006600;">contentLoaderInfo</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>,finished<span style="color: #66cc66;">&#41;</span>;
 	 	 	loadAsset<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">url</span><span style="color: #66cc66;">&#41;</span>;
 	 	<span style="color: #66cc66;">&#125;</span>
 	 	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> loadAsset<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">url</span>:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
 	 	 	<span style="color: #000000; font-weight: bold;">var</span> request:URLRequest = <span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">url</span><span style="color: #66cc66;">&#41;</span>;
 	 	 	loader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span>request<span style="color: #66cc66;">&#41;</span>;
 	 	 <span style="color: #66cc66;">&#125;</span>
 	 	<span style="color: #000000; font-weight: bold;">function</span> finished<span style="color: #66cc66;">&#40;</span>evt:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
 	 	 	_fontsDomain = loader.<span style="color: #006600;">contentLoaderInfo</span>.<span style="color: #006600;">applicationDomain</span>;
 	 	 	registerFonts<span style="color: #66cc66;">&#40;</span>_fontName<span style="color: #66cc66;">&#41;</span>;
 	 	 	dispatchEvent<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Event<span style="color: #66cc66;">&#40;</span>LoadFont.<span style="color: #006600;">COMPLETE</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
 	 	<span style="color: #66cc66;">&#125;</span>
 	 	<span style="color: #000000; font-weight: bold;">function</span> font_ioErrorHandler<span style="color: #66cc66;">&#40;</span>evt:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
 	 	 	dispatchEvent<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Event<span style="color: #66cc66;">&#40;</span>LoadFont.<span style="color: #0066CC;">ERROR</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
 	 	 <span style="color: #66cc66;">&#125;</span>
 	 	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> registerFonts<span style="color: #66cc66;">&#40;</span>fontList:<span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
 	 	 	<span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i:uint = <span style="color: #cc66cc;">0</span>; i <span style="color: #66cc66;">&amp;</span>lt; fontList.<span style="color: #0066CC;">length</span>; i++<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
 	 	 	 	<span style="color: #0066CC;">Font</span>.<span style="color: #006600;">registerFont</span><span style="color: #66cc66;">&#40;</span>getFontClass<span style="color: #66cc66;">&#40;</span>fontList<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
 	 	 	<span style="color: #66cc66;">&#125;</span>
 	 	<span style="color: #66cc66;">&#125;</span>
 	 	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getFontClass<span style="color: #66cc66;">&#40;</span>id:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #000000; font-weight: bold;">Class</span> <span style="color: #66cc66;">&#123;</span>
 	 	 	<span style="color: #b1b100;">return</span> _fontsDomain.<span style="color: #006600;">getDefinition</span><span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span>  as  <span style="color: #000000; font-weight: bold;">Class</span>;
 	 	 <span style="color: #66cc66;">&#125;</span>
 	 	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getFont<span style="color: #66cc66;">&#40;</span>id:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Font</span> <span style="color: #66cc66;">&#123;</span>
 	 	 	<span style="color: #000000; font-weight: bold;">var</span> fontClass:<span style="color: #000000; font-weight: bold;">Class</span> = getFontClass<span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span>;
 	 	 	<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> fontClass    as  <span style="color: #0066CC;">Font</span>;
 	 	<span style="color: #66cc66;">&#125;</span>
 	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.mokisystems.com/blog/flash-as3-loading-fonts/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How Can I Improve My Site&#8217;s Ranking?</title>
		<link>http://www.mokisystems.com/blog/how-can-i-improve-my-sites-ranking/</link>
		<comments>http://www.mokisystems.com/blog/how-can-i-improve-my-sites-ranking/#comments</comments>
		<pubDate>Tue, 22 Apr 2008 21:58:30 +0000</pubDate>
		<dc:creator>andrew</dc:creator>
		
		<category><![CDATA[SEO]]></category>

		<guid isPermaLink="false">http://www.mokisystems.com/blog/how-can-i-improve-my-sites-ranking/</guid>
		<description><![CDATA[This question has entered the minds of website owners hundreds of times. Being on the first page of results within a search engine can mean the difference between success and failure.
In response to the question &#8220;How can I improve my site&#8217;s ranking?&#8221; Google has given the answer.  &#8220;In general, webmasters can improve the rank [...]]]></description>
			<content:encoded><![CDATA[<p>This question has entered the minds of website owners hundreds of times. Being on the first page of results within a search engine can mean the difference between success and failure.</p>
<p>In response to the question &#8220;How can I improve my site&#8217;s ranking?&#8221; Google has given the <a href="http://www.google.com/support/webmasters/bin/answer.py?answer=34432&amp;topic=8524." target="_blank" title="Improve sites ranking">answer.</a>  &#8220;In general, webmasters can improve the rank of their sites by increasing the number of high-quality sites that link to their pages.&#8221;</p>
<p>Hundreds of factors go into determining a sites rank within a search engine, however, possibly the most important is the number of high-quality inbound links to your website. By high-quality we mean sites that themselves rank high in search engines, and are relevant and similar to your websites content.</p>
<p>A simple search on &#8220;Link Submission&#8221; on Google will turn up thousands of websites that will accept, and dispay a link to your site on their site. You could go about submitting to hundreds of these sites, but it will likely not increase you position within any search engine. These submissions can actually hurt your site&#8217;s ranking, not improve it.</p>
<p><strong>So who should I submit my link to?</strong></p>
<p>While trying to avoid submitting your link to a hundred places, there are a few key places that you should submit to. You will want to add your site to the <a href="http://www.google.com/addurl/" target="_blank">Google Index</a>. Yahoo also provides a free site submission into their index <a href="https://siteexplorer.search.yahoo.com/submit" target="_blank" title="Yahoo Submit">here</a>.   You may want to consider adding your site to DMOZ.org.  DMOZ is a web directory which is human edited.  Getting your site listed here will also get your site listed in the Google Directory (Google uses DMOZ.org&#8217;s directory).  You can submit your site to DMOZ <a href="http://www.dmoz.org/add.html" target="_blank" title="Dmoz Submission">here</a>.</p>
<p><strong>Great. Now What?</strong></p>
<p>After you have submitted your site to the major search engines, you&#8217;ll want to trade links with websites that are well placed within your industry. Do a google search on a few keywords that pertain to your website. Lets say &#8220;poodle puppies.&#8221; Get the list of the top 15-20 websites that currently appear on Google or Yahoo under that keyword. Next, write an individual email to each of them asking to trade links with them. You may even consider buying a link on their site.</p>
<p>As soon as they add the links and the search engines become aware that they link to your site, your site&#8217;s ranking will dramatically increase.</p>
<p>The key to success here is not to give up. You should be continually trying to get high quality links to your site as you grow.  My Next article will deal with internally improving your website to increase your ranking on Search Engines. We&#8217;ll talk about <em>layout</em>, <em>structure</em>, <em>meta tags</em>, <em>alt tags</em> and<em> title tags</em> that will affect your site&#8217;s ranking.</p>
<p>Stay Tuned!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mokisystems.com/blog/how-can-i-improve-my-sites-ranking/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
