<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Seventh Sense &#187; Showcase</title>
	<atom:link href="http://sgowtham.net/blog/category/technology/showcase/feed/" rel="self" type="application/rss+xml" />
	<link>http://sgowtham.net/blog</link>
	<description>Rambling about life&#039;s little things, in 7 ≡ 1 (mod 6) fashion</description>
	<lastBuildDate>Tue, 28 Feb 2012 23:25:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<image>
	<title>Seventh Sense</title>
	<url>http://sgowtham.net/images/sg_logo_rss.png</url>
	<link>http://sgowtham.net/blog</link>
	<width>32</width>
	<height>32</height>
	</image>
		<item>
		<title>Logo In RSS Feed &#8211; In WordPress Blogs And Elsewhere</title>
		<link>http://sgowtham.net/blog/2009/02/11/logo-in-rss-feed-in-wordpress-blogs-and-elsewhere/</link>
		<comments>http://sgowtham.net/blog/2009/02/11/logo-in-rss-feed-in-wordpress-blogs-and-elsewhere/#comments</comments>
		<pubDate>Wed, 11 Feb 2009 13:47:52 +0000</pubDate>
		<dc:creator>Gowtham</dc:creator>
				<category><![CDATA[RSS]]></category>
		<category><![CDATA[Showcase]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://sgowtham.net/blog/?p=1718</guid>
		<description><![CDATA[I have been having the need (or want, as you may see fit) to display a logo in my RSS feed &#8211; for my WordPress powered blog as well as home-cooked Showcase. Couple things one needs to keep in mind when designing such logos is the following (information summarized from here): Maximum value for width [...]]]></description>
			<content:encoded><![CDATA[<p>I have been having the need (or want, as you may see fit) to display a logo in my RSS feed &#8211; for my <a href="http://wordpress.org/" target="_blank">WordPress</a> powered blog as well as home-cooked <a href="http://sgowtham.net/showcase/" target="_blank">Showcase</a>. Couple things one needs to keep in mind when designing such logos is the following (information summarized from <a href="http://cyber.law.harvard.edu/rss/rss.html#ltimagegtSubelementOfLtchannelgt" target="_blank">here</a>):</p>
<ol>
<li>Maximum value for width is 144, default value is 88</li>
<li>Maximum value for height is 400, default value is 31</li>
</ol>
<p>In the following two sub-sections, I will show what I did to accomplish this thing.</p>
<p><br clear="all"></p>
<h3 class="blog">Case #1. A WordPress Blog</h3>
<p>It&#8217;s fairly simple to achieve it in that the following lines need to be put into <b>functions.php</b>, found within the theme of your choice. WordPress-provided hook, <em>add_action(&#8216;rss2_head&#8217;, &#8216;function_name&#8217;)</em>, puts this information in an appropriate place within the RSS feed.</p>
<p><br clear="all"></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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rss2_head'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'my_logo_rss'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># The value of &lt;url&gt; tag needs to point to the image. It DOES NOT have
</span><span style="color: #666666; font-style: italic;"># to be within the WordPress folder.
</span><span style="color: #000000; font-weight: bold;">function</span> my_logo_rss<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;image&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&lt;title&gt;&quot;</span> <span style="color: #339933;">.</span> get_bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;/title&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&lt;url&gt;&quot;</span> <span style="color: #339933;">.</span> get_bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'siteurl)'</span><span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;/site_logo_rss.png&lt;/url&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;"># echo &quot;\t&lt;url&gt;http://your-site.com/images/site_logo_rss.png&lt;/url&gt;\n&quot;;
</span>  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&lt;link&gt;&quot;</span> <span style="color: #339933;">.</span> get_bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;/link&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&lt;width&gt;32&lt;/width&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&lt;height&gt;32&lt;/height&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&lt;/image&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><br clear="all"><br />
<img class="framed" src="http://sgowtham.net/blog/files/20090211/screenshot.png" alt="Logo in RSS Feed" title="Logo in RSS Feed"></a></p>
<p class="bpcaption">Logo In RSS Feed &#8211; A WordPress Blog</p>
<p><br clear="all"></p>
<h3 class="blog">Case #2. A Non-WordPress Blog</h3>
<p>It&#8217;s fairly simple to achieve it even here &#8211; as long as one has access to a program/PHP file that generates the RSS feed. Add the following lines to the program, just before the first <em>&lt;item&gt;</em> begins (with values appropriate to your site of course), and that&#8217;s about it.</p>
<p><br clear="all"></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&lt;image&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&lt;title&gt;scenic stopovers&lt;/title&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&lt;url&gt;http://sgowtham.net/images/site_logo_rss.png&lt;/url&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&lt;link&gt;http://sgowtham.net/&lt;/link&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&lt;width&gt;32&lt;/width&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&lt;height&gt;32&lt;/height&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&lt;/image&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><br clear="all"><br />
<img class="framed" src="http://sgowtham.net/blog/files/20090211/screenshot2.png" alt="Logo in RSS Feed" title="Logo in RSS Feed"></a></p>
<p class="bpcaption">Logo In RSS Feed &#8211; A non-WordPress Blog</p>
<p><br clear="all"></p>
<p><br clear="all"></p>
<h3 class="blog">This Does NOT Seem To Be Working!</h3>
<p>Believe it or not, it didn&#8217;t work for me either &#8211; not at least until I cleared out the browser cache and hit the refresh/reload button. I have heard that most RSS readers still don&#8217;t recognize this icon/logo thing yet but it doesn&#8217;t hurt to have it &#8211; when it does show up, it sure does feed our ego!</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsgowtham.net%2Fblog%2F2009%2F02%2F11%2Flogo-in-rss-feed-in-wordpress-blogs-and-elsewhere%2F&amp;title=Logo%20In%20RSS%20Feed%20%26%238211%3B%20In%20WordPress%20Blogs%20And%20Elsewhere" id="wpa2a_2"><img src="http://sgowtham.net/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://sgowtham.net/blog/2009/02/11/logo-in-rss-feed-in-wordpress-blogs-and-elsewhere/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHP &#8211; Displaying Gravatars In A Non-WordPress Application</title>
		<link>http://sgowtham.net/blog/2008/10/20/php-displaying-gravatars-in-a-non-wordpress-application/</link>
		<comments>http://sgowtham.net/blog/2008/10/20/php-displaying-gravatars-in-a-non-wordpress-application/#comments</comments>
		<pubDate>Mon, 20 Oct 2008 23:01:34 +0000</pubDate>
		<dc:creator>Gowtham</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Showcase]]></category>

		<guid isPermaLink="false">http://sgowtham.net/blog/?p=1106</guid>
		<description><![CDATA[Citing their website, an Automattic.com joint:, A gravatar, or globally recognized avatar, is quite simply an avatar image that follows you from weblog to weblog appearing beside your name when you comment on gravatar enabled sites. Avatars help identify your posts on web forums, so why not on weblogs? It&#8217;s free and with one account, [...]]]></description>
			<content:encoded><![CDATA[<p>Citing their <a href="http://www.gravatar.com/" target="_blank">website</a>, an <a href="http://www.automattic.com/" target="_blank">Automattic.com</a> joint:,</p>
<blockquote><p>
A gravatar, or <strong>g</strong>lobally <strong>r</strong>ecognized <strong>avatar</strong>, is quite simply an avatar image that follows you from weblog to weblog appearing beside your name when you comment on gravatar enabled sites. Avatars help identify your posts on web forums, so why not on weblogs?
</p></blockquote>
<p>It&#8217;s free and with one account, one can register and assign multiple email address the same (or different) avatar(s).</p>
<p><br clear="all"></p>
<h3 class="blog">Why?</h3>
<p>For my recent, still on-going, attempts to write a personally satisfying <a href="http://sgowtham.net/showcase/" target="_blank">photoblog software/application</a>, I would like to display the gravatar associated with comment author&#8217;s email address. <em>Would it attract more comments?</em> May be yes, may be no. <em>Would it make comment authors feel good about it?</em> May be yes. It certainly makes both my <a href="http://sgowtham.net/blog/">blog</a> and <a href="http://sgowtham.net/showcase/">photoblog</a> have a nearly consistent theme.</p>
<p><br clear="all"></p>
<h3 class="blog">Requirements</h3>
<p>It is my practice that I do a full/maximal installation of any linux distribution and that takes care of installing Apache (with all the required modules), PHP, MySQL, ImageMagick, etc. I bet there are tons of documents online that you can refer and install them if you don&#8217;t already have them.</p>
<p><br clear="all"></p>
<h3 class="blog">DisplayGravatar.php</h3>
<p>Let us suppose that all the required code goes into a file called <strong>DisplayGravatar.php</strong>. One could otherwise put these lines into a global functions page.</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="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;"># Function that accepts email address, width &amp; rating as input parameters and returns
</span><span style="color: #666666; font-style: italic;"># the URL to the Gravatar associated with that email address.
</span>
<span style="color: #000000; font-weight: bold;">function</span> display_gravatar <span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #339933;">,</span> <span style="color: #000088;">$width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$rating</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;"># MD5 hashed version of requested email address
</span>  <span style="color: #000088;">$hashed_email</span>  <span style="color: #339933;">=</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$gravatar_url</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://www.gravatar.com/avatar.php?&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$gravatar_url</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;gravatar_id=<span style="color: #006699; font-weight: bold;">$hashed_email</span>&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$gravatar_url</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&amp;rating=<span style="color: #006699; font-weight: bold;">$rating</span>&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$gravatar_url</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&amp;size=<span style="color: #006699; font-weight: bold;">$width</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$gravatar_url</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>The following is a sample usage of this function:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
  <span style="color: #666666; font-style: italic;"># Get Gravatar URL
</span>  <span style="color: #666666; font-style: italic;"># Change the width and rating, if necessary
</span>  <span style="color: #000088;">$gravatar_url</span> <span style="color: #339933;">=</span> display_gravatar<span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'80'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'R'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;&lt;img src=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$gravatar_url</span><span style="color: #000099; font-weight: bold;">\&quot;</span> border=<span style="color: #000099; font-weight: bold;">\&quot;</span>0<span style="color: #000099; font-weight: bold;">\&quot;</span> alt=<span style="color: #000099; font-weight: bold;">\&quot;</span>Gravatar<span style="color: #000099; font-weight: bold;">\&quot;</span> title=<span style="color: #000099; font-weight: bold;">\&quot;</span>Gravatar<span style="color: #000099; font-weight: bold;">\&quot;</span> align=<span style="color: #000099; font-weight: bold;">\&quot;</span>left<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><br clear="all"></p>
<h3 class="blog">Screenshots</h3>
<p>When everything goes well, result may look like:</p>
<p><br clear="all"><br />
<img class="framed" src="http://sgowtham.net/blog/files/20081020/display_gravatar_0.png" alt="Gravatar" title="Gravatar"></p>
<p class="bpcaption">When a gravatar is associated with an email address</p>
<p><br clear="all"><br />
<img class="framed" src="http://sgowtham.net/blog/files/20081020/display_gravatar_1.png" alt="Gravatar" title="Gravatar"></p>
<p class="bpcaption">When a gravatar is <u>not</u> associated with an email address</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsgowtham.net%2Fblog%2F2008%2F10%2F20%2Fphp-displaying-gravatars-in-a-non-wordpress-application%2F&amp;title=PHP%20%26%238211%3B%20Displaying%20Gravatars%20In%20A%20Non-WordPress%20Application" id="wpa2a_4"><img src="http://sgowtham.net/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://sgowtham.net/blog/2008/10/20/php-displaying-gravatars-in-a-non-wordpress-application/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>PHP &#8211; Converting Strings To Images</title>
		<link>http://sgowtham.net/blog/2008/08/16/php-converting-strings-to-images/</link>
		<comments>http://sgowtham.net/blog/2008/08/16/php-converting-strings-to-images/#comments</comments>
		<pubDate>Sat, 16 Aug 2008 20:26:51 +0000</pubDate>
		<dc:creator>Gowtham</dc:creator>
				<category><![CDATA[Graphics]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Showcase]]></category>

		<guid isPermaLink="false">http://sgowtham.net/blog/?p=517</guid>
		<description><![CDATA[One of the most primal needs of displaying strings as an image is during form submission and to make sure that a human being (although there is a finite probability that a monkey can accidentally type the same string correctly) types in the string. This form submission can be to accomplish one of many things [...]]]></description>
			<content:encoded><![CDATA[<p>One of the most primal needs of displaying strings as an image is during form submission and to make sure that a human being (although there is a finite probability that a monkey can accidentally type the same string correctly) types in the string. This form submission can be to accomplish one of many things &#8211; posting comments, placing web orders, displaying email addresses, etc. For my recent, still on-going, attempts to write a personally satisfying <a href="http://sgowtham.net/showcase/" target="_blank">photoblog software/application</a>, I need this as part of comment-submission process.</p>
<p><br clear="all"></p>
<h3 class="blog">Requirements</h3>
<p>It is my practice that I do a full/maximal installation of any linux distribution and that takes care of installing Apache (with all the required modules), PHP, MySQL, ImageMagick, etc. I bet there are tons of documents online that you can refer and install them if you don&#8217;t already have them.</p>
<p><br clear="all"></p>
<h3 class="blog">SecureImage.php</h3>
<p>Let us suppose that all the required code goes into a file called <strong>SecureImage.php</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
52
53
54
55
56
57
58
59
60
61
62
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Length of security phrase
</span><span style="color: #000088;">$phrase_length</span>   <span style="color: #339933;">=</span> <span style="color: #cc66cc;">6</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$security_phrase</span> <span style="color: #339933;">=</span> SecurityPhrase<span style="color: #009900;">&#40;</span><span style="color: #000088;">$phrase_length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> SecurityPhrase <span style="color: #009900;">&#40;</span><span style="color: #000088;">$length</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;"># Start with a blank security_phrase
</span>  <span style="color: #000088;">$security_phrase</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;"># Define possible characters
</span>  <span style="color: #666666; font-style: italic;"># Exlude vowels to prevent offensive phrases
</span>  <span style="color: #000088;">$characters</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;0123456789bcdfghjkmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ&quot;</span><span style="color: #339933;">;</span> 
&nbsp;
  <span style="color: #666666; font-style: italic;"># A counter to keep track of number of characters 
</span>  <span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;"># Add random characters to $security_phrase until $length is reached
</span>  <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$length</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
    <span style="color: #666666; font-style: italic;"># Pick a random character from the possible ones
</span>    <span style="color: #000088;">$character</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$characters</span><span style="color: #339933;">,</span> <span style="color: #990000;">mt_rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$possible</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># Avoid repetition of characters
</span>    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">strstr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$security_phrase</span><span style="color: #339933;">,</span> <span style="color: #000088;">$character</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
      <span style="color: #000088;">$security_phrase</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$character</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$i</span><span style="color: #339933;">++;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;"># Temporary location to store the image
</span>  <span style="color: #666666; font-style: italic;"># /var/www/html is the default DocumentRoot in Red Hat like distributions
</span>  <span style="color: #666666; font-style: italic;"># The folder, 'tmp' must have read and write permissions for the apache (or the web) user
</span>  <span style="color: #000088;">$tmp_image_location</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/var/www/html/tmp/&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;"># Filename of the image (PNG)
</span>  <span style="color: #666666; font-style: italic;"># Security Phrase itself will be the filename
</span>  <span style="color: #000088;">$tmp_image_filename</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$tmp_image_location</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$security_phrase</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;.png&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;"># ImageMagick's 'convert' utility and options
</span>  <span style="color: #000088;">$text2img</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/usr/bin/convert '</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$text2img</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">' -background white '</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$text2img</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">' -fill black '</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$text2img</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">' -pointsize 30 '</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$text2img</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">' -gravity West '</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$text2img</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">' -wave 2x80'</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$text2img</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">' label:'</span><span style="color: #339933;">.</span><span style="color: #000088;">$security_phrase</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$text2img</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$tmp_image_filename</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;"># Run the command
</span>  <span style="color: #990000;">system</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$text2img</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;"># Display the image
</span>  <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;&lt;img src=<span style="color: #000099; font-weight: bold;">\&quot;</span>/tmp/<span style="color: #006699; font-weight: bold;">$security_phrase</span>.png<span style="color: #000099; font-weight: bold;">\&quot;</span> border=<span style="color: #000099; font-weight: bold;">\&quot;</span>0<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;
         &lt;br&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$security_phrase</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><br clear="all"></p>
<h3 class="blog">Using This In A Form</h3>
<p>Let us suppose that the form looks something like following:</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
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;POST&quot;</span> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;APPROPRIATE URL&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">table</span> <span style="color: #000066;">border</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">cellpadding</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;5&quot;</span> <span style="color: #000066;">cellspacing</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;3&quot;</span> <span style="color: #000066;">align</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;center&quot;</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">valign</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;top&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">b</span>&gt;</span>Name<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">b</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">valign</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;top&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;name&quot;</span> <span style="color: #000066;">size</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;25&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">font</span> <span style="color: #000066;">size</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">color</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#000066&quot;</span>&gt;</span>
  (Required)
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">font</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">valign</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;top&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">b</span>&gt;</span>Email<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">b</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">valign</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;top&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;email&quot;</span> <span style="color: #000066;">size</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;25&quot;</span>&gt;</span> 
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">font</span> <span style="color: #000066;">size</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">color</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#000066&quot;</span>&gt;</span>
  (Required; must be valid; will not be shared or made public)
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">font</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">valign</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;top&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">b</span>&gt;</span>URL<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">b</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">valign</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;top&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;url&quot;</span> <span style="color: #000066;">size</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;25&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">font</span> <span style="color: #000066;">size</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">color</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#000066&quot;</span>&gt;</span>
  (Optional; please include http://)
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">font</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">valign</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;top&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">b</span>&gt;</span>Security Phrase<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">b</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">valign</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;top&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;?php include<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'SecureImage.php'</span><span style="color: #66cc66;">&#41;</span>; ?&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;security_phrase&quot;</span> <span style="color: #000066;">size</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;25&quot;</span>&gt;</span> 
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">font</span> <span style="color: #000066;">size</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">color</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#000066&quot;</span>&gt;</span>
  (Required; enter the characters shown above)
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">font</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">valign</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;top&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">b</span>&gt;</span>Comments<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">b</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">valign</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;top&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">textarea</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;comments&quot;</span> <span style="color: #000066;">rows</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;6&quot;</span> <span style="color: #000066;">cols</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;40&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">textarea</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;noborder&quot;</span>&gt;</span>
<span style="color: #ddbb00;">&amp;nbsp;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;noborder&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Submit&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;reset&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Clear&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">table</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span></pre></td></tr></table></div>

<p><strong>APPROPRIATE URL</strong> refers to perhaps a PHP script that will process the information submitted by this form.</p>
<p><br clear="all"></p>
<h3 class="blog">Screenshot</h3>
<p><img class="framed" src="http://sgowtham.net/blog/files/20080816/SecureImage.png" title="SecureImage" alt="SecureImage" border="0"></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsgowtham.net%2Fblog%2F2008%2F08%2F16%2Fphp-converting-strings-to-images%2F&amp;title=PHP%20%26%238211%3B%20Converting%20Strings%20To%20Images" id="wpa2a_6"><img src="http://sgowtham.net/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://sgowtham.net/blog/2008/08/16/php-converting-strings-to-images/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Copyrighting Images With Images Using Adobe Photoshop</title>
		<link>http://sgowtham.net/blog/2008/07/21/copyrighting-images-with-images-using-adobe-photoshop/</link>
		<comments>http://sgowtham.net/blog/2008/07/21/copyrighting-images-with-images-using-adobe-photoshop/#comments</comments>
		<pubDate>Mon, 21 Jul 2008 22:00:21 +0000</pubDate>
		<dc:creator>Gowtham</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[Photography]]></category>
		<category><![CDATA[Photoshop]]></category>
		<category><![CDATA[Showcase]]></category>

		<guid isPermaLink="false">http://sgowtham.net/blog/?p=341</guid>
		<description><![CDATA[Disclaimer Below given instructions are what I used to copyright my images on my Apple MacBook Pro running OS X v10.5.x and these may very well work for you. However, please note that you are using these instructions at your very own risk and this website, sgowtham.net, is not responsible for any/all damage caused to [...]]]></description>
			<content:encoded><![CDATA[<h3 class="blog">Disclaimer</h3>
<p>Below given instructions are what I used to copyright my images on my Apple MacBook Pro running OS X v10.5.x and these may very well work for you. However, please note that you are using these instructions at your very own risk and this website, <a href="http://sgowtham.net/" target="_blank">sgowtham.net</a>, is not responsible for any/all damage caused to your property, intellectual or otherwise.</p>
<p><br clear="all"><br />
Most of us take photographs and many of us post them in this vast, nearly infinite internet. Inherent to this process is a desire to put our name on the pictures &#8211; either to protect them from plagiarism or to feed our ego or whatever other reason. There are many software and multiple ways to get this done. Although I don&#8217;t use this method all the frequently, I have tested it on CS2 and CS3 editions of Adobe Photoshop and you might find it useful. In one of my <a href="http://sgowtham.net/blog/2007/10/15/copyrighting-images-with-adobe-photoshop/" target="_blank">previous posts</a>, I had discussed this process and what follows here is a series of steps to use another (smaller) image instead of text to copyright (or just overlay) the main image.</p>
<p><br clear="all"></p>
<h3 class="blog">Get The Images Ready</h3>
<p><font color="#ff0000">Backup the original picture(s)</font>. Using Photoshop (or otherwise), resize your original picture to a reasonable size. 800&#215;600 px is the approximate dimension of my resized picture.</p>
<p><br clear="all"></p>
<h3 class="blog">Start The Process</h3>
<p>Open the resized image in Photoshop and the screen should look something like:</p>
<p><img class="framed" src="http://sgowtham.net/blog/files/20080721/Copyright_00.jpg" alt="Copyrighting Images with Images using Adobe Photoshop" title="Copyrighting Images with Images using Adobe Photoshop" border="0"><br />
<br clear="all"></p>
<p>We could continue this process assuming that there is only one picture to copyright but it is seldom the case. Let us assume that there is a folder full of images that need similar work and since doing all these steps one at a time for each picture can be laborious task, let us take the <b>Photoshop Action</b> approach. To this effect, pick a <strong>New Action</strong> from the <strong>Actions</strong> palette and give it a suitable name:</p>
<p><img class="framed" src="http://sgowtham.net/blog/files/20080721/Copyright_01.jpg" alt="Copyrighting Images with Images using Adobe Photoshop" title="Copyrighting Images with Images using Adobe Photoshop" border="0"><br />
<img class="framed" src="http://sgowtham.net/blog/files/20080721/Copyright_02.jpg" alt="Copyrighting Images with Images using Adobe Photoshop" title="Copyrighting Images with Images using Adobe Photoshop" border="0"><br />
<br clear="all"></p>
<p>Click on <strong>Record</strong> and You should see the Red circular button in the <strong>Actions</strong> palette, indicating the recording is <strong>ON</strong>.</p>
<p><img class="framed" src="http://sgowtham.net/blog/files/20080721/Copyright_03.jpg" alt="Copyrighting Images with Images using Adobe Photoshop" title="Copyrighting Images with Images using Adobe Photoshop" border="0"><br />
<br clear="all"></p>
<p><strong>File &rarr; Open</strong> and select the image which will be used instead of  (or in addition to) the copyright note.</p>
<p><img class="framed" src="http://sgowtham.net/blog/files/20080721/Copyright_04.jpg" alt="Copyrighting Images with Images using Adobe Photoshop" title="Copyrighting Images with Images using Adobe Photoshop" border="0"><br />
<img class="framed" src="http://sgowtham.net/blog/files/20080721/Copyright_05.jpg" alt="Copyrighting Images with Images using Adobe Photoshop" title="Copyrighting Images with Images using Adobe Photoshop" border="0"><br />
<img class="framed" src="http://sgowtham.net/blog/files/20080721/Copyright_06.jpg" alt="Copyrighting Images with Images using Adobe Photoshop" title="Copyrighting Images with Images using Adobe Photoshop" border="0"><br />
<br clear="all"></p>
<p>Click on the small image and press the following key combination: <strong>cmd + A</strong> followed by <strong>cmd + C</strong> (<strong>ctrl + A</strong> followed by <strong>ctrl + C</strong> in Windows).</p>
<p><img class="framed" src="http://sgowtham.net/blog/files/20080721/Copyright_07.jpg" alt="Copyrighting Images with Images using Adobe Photoshop" title="Copyrighting Images with Images using Adobe Photoshop" border="0"><br />
<br clear="all"></p>
<p>Click on the larger image (image to be copyrighted) and press the following key combination: <strong>cmd + V</strong> (<strong>ctrl + V</strong> in Windows).</p>
<p><img class="framed" src="http://sgowtham.net/blog/files/20080721/Copyright_08.jpg" alt="Copyrighting Images with Images using Adobe Photoshop" title="Copyrighting Images with Images using Adobe Photoshop" border="0"><br />
<br clear="all"></p>
<p>Once the smaller image appears as on overlay on top of the larger image, smaller image needs to be properly aligned. To keep track, one may rename the layer that contains smaller image. </p>
<p><img class="framed" src="http://sgowtham.net/blog/files/20080721/Copyright_09.jpg" alt="Copyrighting Images with Images using Adobe Photoshop" title="Copyrighting Images with Images using Adobe Photoshop" border="0"><br />
<img class="framed" src="http://sgowtham.net/blog/files/20080721/Copyright_10.jpg" alt="Copyrighting Images with Images using Adobe Photoshop" title="Copyrighting Images with Images using Adobe Photoshop" border="0"><br />
<img class="framed" src="http://sgowtham.net/blog/files/20080721/Copyright_11.jpg" alt="Copyrighting Images with Images using Adobe Photoshop" title="Copyrighting Images with Images using Adobe Photoshop" border="0"><br />
<img class="framed" src="http://sgowtham.net/blog/files/20080721/Copyright_12.jpg" alt="Copyrighting Images with Images using Adobe Photoshop" title="Copyrighting Images with Images using Adobe Photoshop" border="0"><br />
<img class="framed" src="http://sgowtham.net/blog/files/20080721/Copyright_13.jpg" alt="Copyrighting Images with Images using Adobe Photoshop" title="Copyrighting Images with Images using Adobe Photoshop" border="0"><br />
<br clear="all"></p>
<p>After the last four steps (assuming that you picked <strong>Bottom</strong> &amp; <strong>Right Edges</strong>), the result should look something as follows. As one can note, the overlayed image is too close to the edges. To make it easily readable, select the <strong>Move</strong> tool and nudge the small image layer  &#8211; both in upward and left directions &#8211; by a few keystrokes using the arrow keys.</p>
<p><img class="framed" src="http://sgowtham.net/blog/files/20080721/Copyright_14.jpg" alt="Copyrighting Images with Images using Adobe Photoshop" title="Copyrighting Images with Images using Adobe Photoshop" border="0"><br />
<br clear="all"></p>
<p>Once that&#8217;s done, press the Blue square button in the <strong>Actions</strong> palette to STOP recording.</p>
<p><img class="framed" src="http://sgowtham.net/blog/files/20080721/Copyright_15.jpg" alt="Copyrighting Images with Images using Adobe Photoshop" title="Copyrighting Images with Images using Adobe Photoshop" border="0"><br />
<br clear="all"></p>
<p>That&#8217;s it. Now this sequence of steps can be called as and when needed and the best part is that it can be used with other built-in features of Photoshop to work on folder full of images. Let us assume the following directory structure:</p>
<p><strong>Pictures/Processing/Originals</strong>: contains a <u>copy</u> of the original, resized images.<br />
<strong>Pictures/Processing/Copyrighted</strong>: will contain copyrighted images.</p>
<p><img class="framed" src="http://sgowtham.net/blog/files/20080721/Copyright_16.jpg" alt="Copyrighting Images with Images using Adobe Photoshop" title="Copyrighting Images with Images using Adobe Photoshop" border="0"><br />
<br clear="all"></p>
<p>Pick the appropriate <strong>Quality</strong>. To add smaller image on all the resized images, check <strong>Run Action</strong> under <strong>Preferences</strong> and select <strong>Copyright_Images</strong>. Press <strong>Run</strong> and wait for the process to complete.</p>
<p><img class="framed" src="http://sgowtham.net/blog/files/20080721/Copyright_17.jpg" alt="Copyrighting Images with Images using Adobe Photoshop" title="Copyrighting Images with Images using Adobe Photoshop" border="0"><br />
<br clear="all"></p>
<p>As one particular location of smaller image may not serve well for all images, it may be useful to create more <strong>Photoshop Actions</strong> &#8211; <strong>TopLeft</strong>, <strong>TopRight</strong>, <strong>BottomLeft</strong> and <strong>BottomRight</strong> &#8211; so on and use them as appropriate. It is quite important to retain the location of smaller image &#8211; otherwise the process might complain about not being able to find it.</p>
<p>Comments and/or suggestions, technical or otherwise, about this would be appreciated by myself as well as fellow readers.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsgowtham.net%2Fblog%2F2008%2F07%2F21%2Fcopyrighting-images-with-images-using-adobe-photoshop%2F&amp;title=Copyrighting%20Images%20With%20Images%20Using%20Adobe%20Photoshop" id="wpa2a_8"><img src="http://sgowtham.net/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://sgowtham.net/blog/2008/07/21/copyrighting-images-with-images-using-adobe-photoshop/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Importing Comments From flickr.com</title>
		<link>http://sgowtham.net/blog/2008/07/01/importing-comments-from-flickrcom/</link>
		<comments>http://sgowtham.net/blog/2008/07/01/importing-comments-from-flickrcom/#comments</comments>
		<pubDate>Tue, 01 Jul 2008 14:36:58 +0000</pubDate>
		<dc:creator>Gowtham</dc:creator>
				<category><![CDATA[Flickr]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[RSS]]></category>
		<category><![CDATA[Showcase]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://sgowtham.net/blog/?p=315</guid>
		<description><![CDATA[Disclaimer These instructions/steps worked for me in CentOS 4.0. It may very well work for you on Red Hat-like or other distributions. Please note that if you decide to use these instructions on your machine, you are doing so entirely at your very own discretion and that neither this site, sgowtham.net, nor its author is [...]]]></description>
			<content:encoded><![CDATA[<h3 class="blog">Disclaimer</h3>
<p>These instructions/steps worked for me in CentOS 4.0. It may very well work for you on Red Hat-like or other distributions. Please note that if you decide to use these instructions on your machine, you are doing so entirely at your very own discretion and that neither this site, <a href="http://sgowtham.net/" target="_blank">sgowtham.net</a>, nor its author is responsible for any/all damage &#8211; intellectual or otherwise.</p>
<p><br clear="all"><br />
As much as I would like to see my photographs being commented in my personally satisfying <a href="http://sgowtham.net/showcase/" target="_blank">photoblog</a>, I have recently come to realize (thanks to suggestions from several friends &#8211; <a href="http://flickr.com/photos/nsaligrama/" target="_blank">Nagesh</a> &amp; <a href="http://flickr.com/photos/aragirn/" target="_blank">Kyle</a>) that it&#8217;s not a bad idea to post the same pictures on <a href="http://flickr.com/" target="_blank">flickr.com</a>. For one, the latter is a multi-user platform with users ranging from novice/beginners to advanced professionals. As such, there is a better chance for attracting useful comments. As easy as it might seem to manually enter comments from <em>flickr.com</em>  to my photoblog when there are only few comments, it can become quite tedious and time consuming (at least I expect it to be) with time. To that effect, I did some Google! search to find an XML/RSS parser, modified it to meet my requirements. The procedure/edits follow:</p>
<p><br clear="all"></p>
<h3 class="blog">XML/RSS Parser with PHP</h3>
<p><a href="http://flickr.com/" target="_blank">flickr.com</a> generates an RSS feed for comments that others (or I) make on my photos. This RSS feed contains all the required information &#8211; name, date-time, comment, title of the image, etc. The way I designed my photoblog, the image_name is the unique identifier and when I upload the images to <em>flickr.com</em>, I keep the image name as part of the title. The following script &#8211; <b>flickr2showcase.php</b>, not originally written by me but parts of it heavily modified, does exactly what I want &#8211; extract the information from RSS feed and arrange it in a manner that it can be incorporated into my photoblog (one may refer to the <a href="http://www.sitepoint.com/article/php-xml-parsing-rss-1-0" target="_blank">original script &amp; its documentation</a>).</p>
<p><br clear="all"></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">#! /usr/bin/php
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;"># Connect to the database
</span><span style="color: #000088;">$host</span>     <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;localhost&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dbuser</span>   <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;MYSQL_USERID&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dbpasswd</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;MYSQL_PASSWD&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$database</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;MYSQL_DB&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$connect</span>  <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$host</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dbuser</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dbpasswd</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$database</span><span style="color: #339933;">,</span><span style="color: #000088;">$connect</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> FlickrRSSParser <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;"># In Flickr's RSS file, all the information needed is contained in the &lt;item&gt; 
</span>  <span style="color: #666666; font-style: italic;"># tags in the document. So the first global variable defined will be $insideitem, 
</span>  <span style="color: #666666; font-style: italic;"># which will be set to true when entering an &lt;item&gt; tag and false when exiting one.
</span>  <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$insideitem</span>  <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$tag</span>         <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$title</span>       <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$description</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$link</span>        <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$pubdate</span>     <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;"># This function will be called by the XML parser whenever an opening tag is 
</span>  <span style="color: #666666; font-style: italic;"># encountered
</span>  <span style="color: #666666; font-style: italic;"># $parser will be passed a reference to the XML parser that is being used to 
</span>  <span style="color: #666666; font-style: italic;"># parse the document
</span>  <span style="color: #666666; font-style: italic;"># $tagName is the ALL-UPPERCASE (the PHP manual calls this 'case-folded')
</span>  <span style="color: #666666; font-style: italic;"># version of the name of the opening tag that triggered the event
</span>  <span style="color: #666666; font-style: italic;"># $attrs is an associative array of the attributes that are present in the tag
</span>  <span style="color: #666666; font-style: italic;"># that triggered the event
</span>  <span style="color: #000000; font-weight: bold;">function</span> startElement<span style="color: #009900;">&#40;</span><span style="color: #000088;">$parser</span><span style="color: #339933;">,</span> <span style="color: #000088;">$tagName</span><span style="color: #339933;">,</span> <span style="color: #000088;">$attrs</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">insideitem</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">tag</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$tagName</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$tagName</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;ITEM&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">insideitem</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;"># $parser will be passed a reference to the XML parser that is being used to
</span>  <span style="color: #666666; font-style: italic;"># parse the document
</span>  <span style="color: #666666; font-style: italic;"># $tagName is the case-folded name of the closing tag that triggered the event
</span>  <span style="color: #000000; font-weight: bold;">function</span> endElement<span style="color: #009900;">&#40;</span><span style="color: #000088;">$parser</span><span style="color: #339933;">,</span> <span style="color: #000088;">$tagName</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$tagName</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;ITEM&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;"># Image name: flickr.com displays the title as 'Comment on dsc_100-1234'
</span>      <span style="color: #666666; font-style: italic;"># The filename is the 3rd array element
</span>      <span style="color: #000088;">$title</span>        <span style="color: #339933;">=</span> <span style="color: #990000;">htmlspecialchars</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$title</span>        <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$title</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$filename</span>     <span style="color: #339933;">=</span> <span style="color: #000088;">$title</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;"># Date/Time the comment was made (yyyy-mm-dd hh:mm:ss format)
</span>      <span style="color: #000088;">$pubdate</span>      <span style="color: #339933;">=</span> <span style="color: #990000;">htmlspecialchars</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pubdate</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$pubdate</span>      <span style="color: #339933;">=</span> <span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pubdate</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$pubdate</span>      <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y-m-d H:i:s&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$pubdate</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000088;">$paragraphs</span>   <span style="color: #339933;">=</span> <span style="color: #990000;">htmlspecialchars</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">description</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$paragraphs</span>   <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&amp;lt;/p&amp;gt;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$paragraphs</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;"># The description contains the link to comment-author's flickr profile and 
</span>      <span style="color: #666666; font-style: italic;"># comment-author's name (first &lt;p&gt;&lt;/p&gt; section)
</span>      <span style="color: #000088;">$paragraph0</span>   <span style="color: #339933;">=</span> <span style="color: #000088;">$paragraphs</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$authorurl</span>    <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&amp;quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$paragraph0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$author_url</span>   <span style="color: #339933;">=</span> <span style="color: #000088;">$authorurl</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000088;">$authorname0</span>  <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&amp;gt;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$paragraph0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$authorname1</span>  <span style="color: #339933;">=</span> <span style="color: #000088;">$authorname0</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$authorname2</span>  <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&amp;lt;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$authorname1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$author_name</span>  <span style="color: #339933;">=</span> <span style="color: #000088;">$authorname2</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;"># The description also contains the comment-text (second &lt;p&gt;&lt;/p&gt; section)
</span>      <span style="color: #666666; font-style: italic;"># Basic substitutions are done, via ereg_replace(), to get the appropriate part
</span>      <span style="color: #666666; font-style: italic;"># mysql_real_escape_string() is used to make sure comment_text is in MySQL friendly fashion
</span>      <span style="color: #000088;">$paragraph1</span>   <span style="color: #339933;">=</span> <span style="color: #000088;">$paragraphs</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$commenttext</span>  <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&amp;lt;p&amp;gt;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$paragraph1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$comment_text</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$commenttext</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$comment_text</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ereg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&amp;lt;br /&amp;gt;&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&lt;br&gt;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$comment_text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$comment_text</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$comment_text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;"># The description also contains a link to image-thumbnail (second &lt;p&gt;&lt;/p&gt; section)
</span>      <span style="color: #666666; font-style: italic;"># but it's not required in this process - as such, it's ignored
</span>
      <span style="color: #666666; font-style: italic;"># flickr.com's IP address
</span>      <span style="color: #000088;">$flickr_ip</span>    <span style="color: #339933;">=</span> <span style="color: #990000;">gethostbyname</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'www.flickr.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;"># comments_table structure
</span>      <span style="color: #666666; font-style: italic;"># CREATE TABLE IF NOT EXISTS `comments_table` (
</span>      <span style="color: #666666; font-style: italic;">#  `id`              int(11)      NOT NULL auto_increment,
</span>      <span style="color: #666666; font-style: italic;">#  `datetime`        DATETIME     NOT NULL default '0000-00-00 00:00:00',
</span>      <span style="color: #666666; font-style: italic;">#  `imagename`       varchar(254) NOT NULL,
</span>      <span style="color: #666666; font-style: italic;">#  `authorip`        varchar(254) NOT NULL default '000.000.000.000',
</span>      <span style="color: #666666; font-style: italic;">#  `authorhostname`  varchar(254) NOT NULL default 'localhost.localdomain',
</span>      <span style="color: #666666; font-style: italic;">#  `authorname`      varchar(254) NOT NULL default 'Unknown',
</span>      <span style="color: #666666; font-style: italic;">#  `authoremail`     varchar(254) NOT NULL default 'Unknown',
</span>      <span style="color: #666666; font-style: italic;">#  `authorurl`       varchar(254) NOT NULL default 'Unknown',
</span>      <span style="color: #666666; font-style: italic;">#  `comments`        text,
</span>      <span style="color: #666666; font-style: italic;">#  `status`          varchar(3) NOT NULL default 'No',
</span>      <span style="color: #666666; font-style: italic;">#
</span>      <span style="color: #666666; font-style: italic;">#  UNIQUE KEY `id` (`id`)
</span>      <span style="color: #666666; font-style: italic;"># ) ENGINE=MyISAM DEFAULT CHARSET latin1 AUTO_INCREMENT=1 ;
</span>      <span style="color: #666666; font-style: italic;">#
</span>      <span style="color: #666666; font-style: italic;"># CREATE UNIQUE INDEX author_datetime ON `comments_table` (`authorname`,`datetime`);
</span>      <span style="color: #666666; font-style: italic;">#
</span>
      <span style="color: #666666; font-style: italic;"># Enter into the comments_table in database
</span>      <span style="color: #666666; font-style: italic;"># INSERT IGNORE makes sure that duplicate entries, when exist, 
</span>      <span style="color: #666666; font-style: italic;"># are ignored during insertion
</span>      <span style="color: #000088;">$sql_q</span>        <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;INSERT IGNORE INTO `MYSQL_DB`.`comments_table` &quot;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$sql_q</span>       <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;VALUES ('', '<span style="color: #006699; font-weight: bold;">$pubdate</span>', '<span style="color: #006699; font-weight: bold;">$filename</span>.jpg', '<span style="color: #006699; font-weight: bold;">$flickr_ip</span>', &quot;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$sql_q</span>       <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;'flickr.com', '<span style="color: #006699; font-weight: bold;">$author_name</span>', 'flickr@your-domain.com', &quot;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$sql_q</span>       <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;'<span style="color: #006699; font-weight: bold;">$author_url</span>', '<span style="color: #006699; font-weight: bold;">$comment_text</span>', 'Yes'); &quot;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$result</span>       <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql_q</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Invalid query: '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
&nbsp;
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span>       <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">description</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">link</span>        <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pubdate</span>     <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">insideitem</span>  <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;"># $parser will be passed a reference to the XML parser that is being used to
</span>  <span style="color: #666666; font-style: italic;"># parse the document
</span>  <span style="color: #666666; font-style: italic;"># $data is a string of text appearing between XML tags in the document. 
</span>  <span style="color: #666666; font-style: italic;"># The text between two tags will not necessarily trigger a single event. 
</span>  <span style="color: #666666; font-style: italic;"># Blocks of text spread over multiple lines will cause one event per line, 
</span>  <span style="color: #666666; font-style: italic;"># with each event being passed the $data for that line.
</span>  <span style="color: #000000; font-weight: bold;">function</span> characterData<span style="color: #009900;">&#40;</span><span style="color: #000088;">$parser</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">insideitem</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">tag</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;TITLE&quot;</span><span style="color: #339933;">:</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$data</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;DESCRIPTION&quot;</span><span style="color: #339933;">:</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">description</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$data</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;PUBDATE&quot;</span><span style="color: #339933;">:</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pubdate</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$data</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;LINK&quot;</span><span style="color: #339933;">:</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">link</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$data</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Create an XML parser
</span><span style="color: #666666; font-style: italic;"># Just as one must create a database connection in PHP to interact with a database, 
</span><span style="color: #666666; font-style: italic;"># one must create an XML parser to read in an XML file. In this case, a reference to 
</span><span style="color: #666666; font-style: italic;"># the parser is stored in $xml_parser.
</span><span style="color: #000088;">$xml_parser</span> <span style="color: #339933;">=</span> <span style="color: #990000;">xml_parser_create</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$rss_parser</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FlickrRSSParser<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">xml_set_object</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml_parser</span><span style="color: #339933;">,&amp;</span><span style="color: #000088;">$rss_parser</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># This function specifies the functions that an XML parser should 
</span><span style="color: #666666; font-style: italic;"># use to process the events generated opening and closing tags. 
</span><span style="color: #666666; font-style: italic;"># In this case, the parser is the one stored in our $xml_parser variable, 
</span><span style="color: #666666; font-style: italic;"># while the functions are called startElement() and endElement()
</span>
<span style="color: #990000;">xml_set_element_handler</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml_parser</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;startElement&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;endElement&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># This function specifies the function that the XML parser should use 
</span><span style="color: #666666; font-style: italic;"># to process character data appearing between tags in an XML document. 
</span><span style="color: #666666; font-style: italic;"># The function chosen to process character data is called characterData()
</span><span style="color: #990000;">xml_set_character_data_handler</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml_parser</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;characterData&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Flickr's RSS Feed Comments URL must be entered here
</span><span style="color: #000088;">$rss</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;FLICKR_RSS_FEED_FOR_COMMENTS&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Open the specified URL for reading
</span><span style="color: #000088;">$fp</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rss</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;r&quot;</span><span style="color: #009900;">&#41;</span>
  or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Error reading RSS data.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fread</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4096</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;"># This function sends all or part of an XML document to the parser for it 
</span>  <span style="color: #666666; font-style: italic;"># to process. The endOfDocument parameter should be set to true if the 
</span>  <span style="color: #666666; font-style: italic;"># data marks the end of of XML document, or false if more of the document 
</span>  <span style="color: #666666; font-style: italic;"># will follow in a subsequent call to xml_parse(). This allows the parser to 
</span>  <span style="color: #666666; font-style: italic;"># correctly catch unclosed tags at the end of the document and so forth. 
</span>  <span style="color: #666666; font-style: italic;"># In this case, the parser is once again $xml_parser. The $data variable 
</span>  <span style="color: #666666; font-style: italic;"># (up to 4KB in size) retrieved from the file with fread() is passed as the 
</span>  <span style="color: #666666; font-style: italic;"># data to be processed, while the feof() is used to determine whether 
</span>  <span style="color: #666666; font-style: italic;"># PHP has reached the end of the XML file or not, thus providing the 
</span>  <span style="color: #666666; font-style: italic;"># required endOfDocument parameter. If an error occurs in the parsing of 
</span>  <span style="color: #666666; font-style: italic;"># the document, the error message is printed out along with the line of the 
</span>  <span style="color: #666666; font-style: italic;"># file at which it occurs with xml_error_string, xml_get_error_code() and 
</span>  <span style="color: #666666; font-style: italic;"># xml_get_current_line_number()
</span>  <span style="color: #990000;">xml_parse</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml_parser</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #339933;">,</span> <span style="color: #990000;">feof</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;XML error: <span style="color: #009933; font-weight: bold;">%s</span> at line <span style="color: #009933; font-weight: bold;">%d</span>&quot;</span><span style="color: #339933;">,</span>
      <span style="color: #990000;">xml_error_string</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">xml_get_error_code</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml_parser</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
      <span style="color: #990000;">xml_get_current_line_number</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml_parser</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Although all memory resources are freed at the end of a PHP script, 
</span><span style="color: #666666; font-style: italic;"># one may wish to free up the memory used by the XML parser if the 
</span><span style="color: #666666; font-style: italic;"># script will perform other potentially memory-intensive tasks after it 
</span><span style="color: #666666; font-style: italic;"># parses the XML data. This function destroys the specified XML parser, 
</span><span style="color: #666666; font-style: italic;"># thus freeing up resources and memory it may have allocated for parsing.
</span><span style="color: #990000;">xml_parser_free</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml_parser</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><br clear="all"><br />
To make sure that I don&#8217;t miss any comments, I run this above script via a cron-job, twice a day. To see this in action, one may compare the same image entries in my photoblog as well as on<em> flickr</em>: <a href="http://sgowtham.net/showcase/2008/06/21/great-blue-heron" target="_blank">Photoblog Entry</a> | <a href="http://www.flickr.com/photos/sgowtham/2613670334/" target="_blank">Flickr.com Entry</a></p>
<p>Things seem to be working without any problem so far but that doesn&#8217;t necessarily mean the code/work is without errors and/or bugs. As they show up, I will try to post work-around for them.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsgowtham.net%2Fblog%2F2008%2F07%2F01%2Fimporting-comments-from-flickrcom%2F&amp;title=Importing%20Comments%20From%20flickr.com" id="wpa2a_10"><img src="http://sgowtham.net/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://sgowtham.net/blog/2008/07/01/importing-comments-from-flickrcom/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>File Uploads Via PHP : Specific MIME Types</title>
		<link>http://sgowtham.net/blog/2008/06/11/file-uploads-via-php-specific-mime-types/</link>
		<comments>http://sgowtham.net/blog/2008/06/11/file-uploads-via-php-specific-mime-types/#comments</comments>
		<pubDate>Wed, 11 Jun 2008 23:14:40 +0000</pubDate>
		<dc:creator>Gowtham</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Showcase]]></category>

		<guid isPermaLink="false">http://sgowtham.net/blog/?p=312</guid>
		<description><![CDATA[Disclaimer These instructions/steps worked for me in CentOS. It may very well work for you on Red Hat-like or other distributions. Please note that if you decide to use these instructions on your machine, you are doing so entirely at your very own discretion and that neither this site, sgowtham.net, nor its author is responsible [...]]]></description>
			<content:encoded><![CDATA[<h3 class="blog">Disclaimer</h3>
<p>These instructions/steps worked for me in CentOS. It may very well work for you on Red Hat-like or other distributions. Please note that if you decide to use these instructions on your machine, you are doing so entirely at your very own discretion and that neither this site, <a href="http://sgowtham.net/" target="_blank">sgowtham.net</a>, nor its author is responsible for any/all damage &#8211; intellectual or otherwise.</p>
<p><br clear="all"><br />
During my recent, still on-going, attempts to write a personally satisfying <a href="http://sgowtham.net/showcase/" target="_blank">photoblog software/application</a>, I happened to learn about File Uploads using PHP and in my <a href="http://sgowtham.net/blog/2008/06/08/file-upload-via-php/" target="_blank">previous post</a>, I discussed the general procedure for doing so. There are numerous articles on the web and in the books, but what follows here is what worked for me &#8211; it is expected to serve as a Note2Self but if you find it useful, please feel free to do so.</p>
<p><br clear="all"></p>
<h3 class="blog">A Form To Select The File</h3>
<p>This portion is exactly the same as in previous post but for completeness sake, here it is. Let us suppose that the HTML file that displays this form is called <b>NewFile.html</b> and the PHP file that does the actual uploading work (and some more) is called <b>Uploader.php</b>.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!-- The data encoding type, enctype, MUST be specified as below --&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span> <span style="color: #000066;">enctype</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;multipart/form-data&quot;</span> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Uploader.php&quot;</span> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;POST&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">table</span> <span style="color: #000066;">align</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;left&quot;</span> <span style="color: #000066;">cellpadding</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;5&quot;</span> <span style="color: #000066;">cellspacing</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;5&quot;</span> <span style="color: #000066;">border</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;100%&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">align</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;left&quot;</span> <span style="color: #000066;">valign</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;top&quot;</span>&gt;</span>
        Select A File
      <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
&nbsp;
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">align</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;left&quot;</span> <span style="color: #000066;">valign</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;top&quot;</span>&gt;</span>
        <span style="color: #808080; font-style: italic;">&lt;!-- MAX_FILE_SIZE (measured in bytes) must precede the file input field and its value </span>
<span style="color: #808080; font-style: italic;">        is the maximum filesize accepted by PHP. Fooling this setting on the browser side is </span>
<span style="color: #808080; font-style: italic;">        quite easy, so never rely on files with a greater size being blocked by this feature. </span>
<span style="color: #808080; font-style: italic;">        The PHP settings for maximum-size, however, cannot be fooled. This form element </span>
<span style="color: #808080; font-style: italic;">        should always be used as it saves users the trouble of waiting for a big file being </span>
<span style="color: #808080; font-style: italic;">        transferred only to find that it was too big and the transfer failed. --&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hidden&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;MAX_FILE_SIZE&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;4194304&quot;</span>&gt;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;">&lt;!-- Name of input element determines name in $_FILES array.</span>
<span style="color: #808080; font-style: italic;">        uploaded_file is the reference assigned in the form. This will be needed to </span>
<span style="color: #808080; font-style: italic;">        tell the $_FILES array which file should be handled --&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;uploaded_file&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;file&quot;</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
&nbsp;
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">align</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;left&quot;</span> <span style="color: #000066;">valign</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;top&quot;</span>&gt;</span>
        <span style="color: #ddbb00;">&amp;nbsp;</span>
      <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
&nbsp;
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">align</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;left&quot;</span> <span style="color: #000066;">valign</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;top&quot;</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Upload This File&quot;</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">table</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></td></tr></table></div>

<p><br clear="all"></p>
<h3 class="blog">Uploader.php</h3>
<p>Suppose that the end-user selected a file to upload and hit the <b>Upload This File</b> button. Now, the file, <b>Uploader.php</b> takes over and does a few things. But let us suppose that only image file types (JPEG, GIF, PNG) are to be allowed as <em>uploadable</em> types. Let us also suppose that the image file so uploaded needs to be thumbnailed and put in a folder called <strong>thumbnails</strong> (located under the uploads folder). The source code follows:</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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;"># Some other MIME types are as follows
</span><span style="color: #666666; font-style: italic;"># $_FILES['uploaded_file']['type'] == 'application/pdf'
</span><span style="color: #666666; font-style: italic;"># $_FILES['uploaded_file']['type'] == 'application/xml'  
</span><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'uploaded_file'</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: #0000ff;">'image/gif'</span><span style="color: #009900;">&#41;</span>    <span style="color: #339933;">||</span>
     <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'uploaded_file'</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: #0000ff;">'image/png'</span><span style="color: #009900;">&#41;</span>    <span style="color: #339933;">||</span>
     <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'uploaded_file'</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: #0000ff;">'image/jpeg'</span><span style="color: #009900;">&#41;</span>   <span style="color: #339933;">||</span>
     <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'uploaded_file'</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: #0000ff;">'image/pjpeg'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span>
     <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'uploaded_file'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'size'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">4194304</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'uploaded_file'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;"># The error code  associated with this file upload.
</span>    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Error: &quot;</span>     <span style="color: #339933;">.</span> <span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'uploaded_file'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;br&gt;&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: #666666; font-style: italic;"># The original name of the file on the client machine.
</span>    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Upload: &quot;</span>    <span style="color: #339933;">.</span> <span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'uploaded_file'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;br&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># The mime type of the file, if the browser provided this information. 
</span>    <span style="color: #666666; font-style: italic;"># This mime type is however not checked on the PHP side and therefore it's value should
</span>    <span style="color: #666666; font-style: italic;"># should not be taken for granted.
</span>    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Type: &quot;</span>      <span style="color: #339933;">.</span> <span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'uploaded_file'</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: #0000ff;">&quot;&lt;br&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># The size, in bytes, of the uploaded file.
</span>    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Size: &quot;</span>      <span style="color: #339933;">.</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'uploaded_file'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'size'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">1024</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; kB&lt;br&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># The temporary filename of the file in which the uploaded file was stored on the server.
</span>    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Stored in: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'uploaded_file'</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: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;br&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># Where the file is going to be placed and thumbnail will be creatd; choose this judiciously
</span>    <span style="color: #666666; font-style: italic;"># These locations needs to have 'write' permissions for 'apache' (or the web-user)
</span>    <span style="color: #000088;">$target_path</span>       <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;tmp/&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$target_thumb_path</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$target_path</span>/thumbnails/&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">is_writable</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$target_path</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Cannot be uploaded to the specified directory. Please change permission  to 777.'</span><span style="color: #009900;">&#41;</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: #339933;">!</span><span style="color: #990000;">is_writable</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$target_thumb_path</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Thumbnail cannot be created. Please change permission  to 777.'</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;"># This is the temporary file created by PHP
</span>    <span style="color: #000088;">$uploaded_file</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'uploaded_file'</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: #339933;">;</span>
    <span style="color: #000088;">$target_path</span>   <span style="color: #339933;">=</span> <span style="color: #000088;">$target_path</span> <span style="color: #339933;">.</span> <span style="color: #990000;">basename</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'uploaded_file'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># Create an image from the $uploaded_file so that it can be thumbnailed
</span>    <span style="color: #000088;">$src</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatefromjpeg</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$uploaded_file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># Extract the original size of the uploaded image
</span>    <span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">=</span><span style="color: #990000;">getimagesize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$uploaded_file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># Let the thumbnail be 150 pixels in width, height adjusted based on original aspect ratio
</span>    <span style="color: #000088;">$new_width</span>   <span style="color: #339933;">=</span> <span style="color: #cc66cc;">150</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$new_height</span>  <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$height</span><span style="color: #339933;">/</span><span style="color: #000088;">$width</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #000088;">$new_width</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$tmp</span>         <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatetruecolor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$new_width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$new_height</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># The following line does the thumbnailing
</span>    <span style="color: #990000;">imagecopyresampled</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmp</span><span style="color: #339933;">,</span> <span style="color: #000088;">$src</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: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$new_width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$new_height</span><span style="color: #339933;">,</span> <span style="color: #000088;">$width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># Write the thumbnailed image to disk
</span>    <span style="color: #666666; font-style: italic;"># Check/modify this part for other image types
</span>    <span style="color: #000088;">$filename</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$target_thumb_path</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'uploaded_file'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">imagejpeg</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmp</span><span style="color: #339933;">,</span> <span style="color: #000088;">$filename</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># PHP will clean up the temporary files after the request is completed
</span>    <span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$src</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmp</span><span style="color: #009900;">&#41;</span>
&nbsp;
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">move_uploaded_file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'uploaded_file'</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: #339933;">,</span> <span style="color: #000088;">$target_path</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;The file &quot;</span> <span style="color: #339933;">.</span>  <span style="color: #990000;">basename</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'uploaded_file'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; has been uploaded&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: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;There was an error uploading the file, please try again!&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Invalid file type!&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsgowtham.net%2Fblog%2F2008%2F06%2F11%2Ffile-uploads-via-php-specific-mime-types%2F&amp;title=File%20Uploads%20Via%20PHP%20%3A%20Specific%20MIME%20Types" id="wpa2a_12"><img src="http://sgowtham.net/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://sgowtham.net/blog/2008/06/11/file-uploads-via-php-specific-mime-types/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>File Upload Via PHP</title>
		<link>http://sgowtham.net/blog/2008/06/08/file-upload-via-php/</link>
		<comments>http://sgowtham.net/blog/2008/06/08/file-upload-via-php/#comments</comments>
		<pubDate>Sun, 08 Jun 2008 16:27:40 +0000</pubDate>
		<dc:creator>Gowtham</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Showcase]]></category>

		<guid isPermaLink="false">http://sgowtham.net/blog/?p=311</guid>
		<description><![CDATA[Disclaimer These instructions/steps worked for me in CentOS. It may very well work for you on Red Hat-like or other distributions. Please note that if you decide to use these instructions on your machine, you are doing so entirely at your very own discretion and that neither this site, sgowtham.net, nor its author is responsible [...]]]></description>
			<content:encoded><![CDATA[<h3 class="blog">Disclaimer</h3>
<p>These instructions/steps worked for me in CentOS. It may very well work for you on Red Hat-like or other distributions. Please note that if you decide to use these instructions on your machine, you are doing so entirely at your very own discretion and that neither this site, <a href="http://sgowtham.net/" target="_blank">sgowtham.net</a>, nor its author is responsible for any/all damage &#8211; intellectual or otherwise.</p>
<p><br clear="all"><br />
During my recent, still on-going, attempts to write a personally satisfying <a href="http://sgowtham.net/showcase/" target="_blank">photoblog software/application</a>, I happened to learn about File Uploads using PHP. There are numerous articles on the web and in the books, but what follows here is what worked for me &#8211; it is expected to serve as a Note2Self but if you find it useful, please feel free to do so.</p>
<p><br clear="all"></p>
<h3 class="blog">A Form To Select The File</h3>
<p>Let us suppose that the HTML file that displays this form is called <b>NewFile.html</b> and the PHP file that does the actual uploading work (and some more) is called <b>Uploader.php</b>.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!-- The data encoding type, enctype, MUST be specified as below --&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span> <span style="color: #000066;">enctype</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;multipart/form-data&quot;</span> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Uploader.php&quot;</span> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;POST&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">table</span> <span style="color: #000066;">align</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;left&quot;</span> <span style="color: #000066;">cellpadding</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;5&quot;</span> <span style="color: #000066;">cellspacing</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;5&quot;</span> <span style="color: #000066;">border</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;100%&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">align</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;left&quot;</span> <span style="color: #000066;">valign</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;top&quot;</span>&gt;</span>
        Select A File
      <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
&nbsp;
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">align</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;left&quot;</span> <span style="color: #000066;">valign</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;top&quot;</span>&gt;</span>
        <span style="color: #808080; font-style: italic;">&lt;!-- MAX_FILE_SIZE (measured in bytes) must precede the file input field and its value </span>
<span style="color: #808080; font-style: italic;">        is the maximum filesize accepted by PHP. Fooling this setting on the browser side is </span>
<span style="color: #808080; font-style: italic;">        quite easy, so never rely on files with a greater size being blocked by this feature. </span>
<span style="color: #808080; font-style: italic;">        The PHP settings for maximum-size, however, cannot be fooled. This form element </span>
<span style="color: #808080; font-style: italic;">        should always be used as it saves users the trouble of waiting for a big file being </span>
<span style="color: #808080; font-style: italic;">        transferred only to find that it was too big and the transfer failed. --&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hidden&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;MAX_FILE_SIZE&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;4194304&quot;</span>&gt;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;">&lt;!-- Name of input element determines name in $_FILES array.</span>
<span style="color: #808080; font-style: italic;">        uploaded_file is the reference assigned in the form. This will be needed to </span>
<span style="color: #808080; font-style: italic;">        tell the $_FILES array which file should be handled --&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;uploaded_file&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;file&quot;</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
&nbsp;
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">align</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;left&quot;</span> <span style="color: #000066;">valign</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;top&quot;</span>&gt;</span>
        <span style="color: #ddbb00;">&amp;nbsp;</span>
      <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
&nbsp;
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">align</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;left&quot;</span> <span style="color: #000066;">valign</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;top&quot;</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Upload This File&quot;</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">table</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></td></tr></table></div>

<p><br clear="all"></p>
<h3 class="blog">Uploader.php</h3>
<p>Suppose that the end-user selected a file to upload and hit the <b>Upload This File</b> button. Now, the file, <b>Uploader.php</b> takes over and does a few things. The source code follows:</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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'uploaded_file'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;"># The error code  associated with this file upload.
</span>  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Error: &quot;</span>     <span style="color: #339933;">.</span> <span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'uploaded_file'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;br&gt;&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: #666666; font-style: italic;"># The original name of the file on the client machine.
</span>  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Upload: &quot;</span>    <span style="color: #339933;">.</span> <span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'uploaded_file'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;br&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;"># The mime type of the file, if the browser provided this information. 
</span>  <span style="color: #666666; font-style: italic;"># This mime type is however not checked on the PHP side and therefore it's value should
</span>  <span style="color: #666666; font-style: italic;"># should not be taken for granted.
</span>  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Type: &quot;</span>      <span style="color: #339933;">.</span> <span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'uploaded_file'</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: #0000ff;">&quot;&lt;br&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;"># The size, in bytes, of the uploaded file.
</span>  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Size: &quot;</span>      <span style="color: #339933;">.</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'uploaded_file'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'size'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">1024</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; kB&lt;br&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;"># The temporary filename of the file in which the uploaded file was stored on the server.
</span>  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Stored in: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'uploaded_file'</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: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;br&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;"># Where the file is going to be placed; choose this judiciously
</span>  <span style="color: #666666; font-style: italic;"># This location needs to have 'write' permissions for 'apache' (or the web-user)
</span>  <span style="color: #000088;">$target_path</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;tmp/&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">is_writable</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$target_path</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Cannot be uploaded to the specified directory. Please change permission  to 777.'</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;"># This is the temporary file created by PHP.
</span>  <span style="color: #000088;">$uploaded_file</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'uploaded_file'</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: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$target_path</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$target_path</span> <span style="color: #339933;">.</span> <span style="color: #990000;">basename</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'uploaded_file'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">move_uploaded_file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'uploaded_file'</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: #339933;">,</span> <span style="color: #000088;">$target_path</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;The file &quot;</span> <span style="color: #339933;">.</span>  <span style="color: #990000;">basename</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'uploaded_file'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; has been uploaded&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: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;There was an error uploading the file, please try again!&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><br clear="all"></p>
<h3 class="blog">Specific MIME Type</h3>
<p>The purpose of this code, as I mentioned before, was to be part of the photoblog software and as such, it wouldn&#8217;t make much sense to upload anything but graphic files (JPEG/GIF/PNG). Also, once the  graphic file is uploaded to the server, more often than not it needs to be resized (thumbnails). I will probably include those parts in a subsequent post.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsgowtham.net%2Fblog%2F2008%2F06%2F08%2Ffile-upload-via-php%2F&amp;title=File%20Upload%20Via%20PHP" id="wpa2a_14"><img src="http://sgowtham.net/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://sgowtham.net/blog/2008/06/08/file-upload-via-php/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

