<?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>bgallz.org &#124; Web coding &#38; design tutorials, scripts, resources and more. &#187; Tutorials</title>
	<atom:link href="http://bgallz.org/category/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://bgallz.org</link>
	<description>Web coding &#38; design tutorials, scripts, resources and more.</description>
	<lastBuildDate>Tue, 10 Jan 2012 00:58:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Building a Battlefield 3 Machine</title>
		<link>http://bgallz.org/1023/building-battlefield-3-machine/</link>
		<comments>http://bgallz.org/1023/building-battlefield-3-machine/#comments</comments>
		<pubDate>Tue, 23 Aug 2011 03:17:27 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Gaming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[amd]]></category>
		<category><![CDATA[battlefield 3]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[building]]></category>
		<category><![CDATA[computer]]></category>
		<category><![CDATA[intel]]></category>
		<category><![CDATA[machine]]></category>
		<category><![CDATA[motherboard]]></category>
		<category><![CDATA[pc]]></category>
		<category><![CDATA[processor]]></category>
		<category><![CDATA[video card]]></category>
		<category><![CDATA[windows 7]]></category>
		<category><![CDATA[windows xp]]></category>

		<guid isPermaLink="false">http://bgallz.org/?p=1023</guid>
		<description><![CDATA[Battlefield 3 will hit the shelves October 25th, 2011 for the PC, Xbox 360, and Playstation 3. If you are a PC gamer you know you are going to want a powerful machine to experience this much anticipated release. Battlefield 3 introduces the Frostbite 2.0 engine which is based on the 1.5 engine seen in Bad Company 2, so the ...]]></description>
			<content:encoded><![CDATA[<p>Battlefield 3 will hit the shelves October 25th, 2011 for the PC, Xbox 360, and Playstation 3. If you are a PC gamer you know you are going to want a powerful machine to experience this much anticipated release. Battlefield 3 introduces the Frostbite 2.0 engine which is based on the 1.5 engine seen in Bad Company 2, so the system requirements will be similar.</p>
<p><span style="color: #666699;"><strong>Minimum System Requirements:</strong></span></p>
<p><span style="color: #666699;"><span style="text-decoration: underline;">OS</span>: Windows Vista or Windows 7</span><br />
<span style="color: #666699;"> <span style="text-decoration: underline;">Processor</span>: Core 2 Duo @ 2.0GHz</span><br />
<span style="color: #666699;"> <span style="text-decoration: underline;">RAM</span>: 2GB</span><br />
<span style="color: #666699;"> <span style="text-decoration: underline;">Graphic card</span>: DirectX 10 or 11 compatible Nvidia or AMD ATI card.</span><br />
<span style="color: #666699;"> <span style="text-decoration: underline;">Graphics card memory</span>: 512 MB</span><br />
<span style="color: #666699;"> <span style="text-decoration: underline;">Hard drive</span>: 15 GB for disc version or 10 GB for digital version</span></p>
<p><span style="color: #666699;"><strong>Recommended System Requirements:</strong></span></p>
<p><span style="color: #666699;"><span style="text-decoration: underline;">OS</span>: Windows 7 64-bit</span><br />
<span style="color: #666699;"> <span style="text-decoration: underline;">Processor</span>: Quad-core Intel or AMD CPU</span><br />
<span style="color: #666699;"> <span style="text-decoration: underline;">RAM</span>: 4GB</span><br />
<span style="color: #666699;"> <span style="text-decoration: underline;">Graphics card</span>: DirectX 11 Nvidia or AMD ATI card, GeForce GTX 460, Radeon Radeon HD 6850</span><br />
<span style="color: #666699;"> <span style="text-decoration: underline;">Graphics card memory</span>: 1 GB</span><br />
<span style="color: #666699;"> <span style="text-decoration: underline;">Hard drive</span>: 15 GB for disc version or 10 GB for digital version</span></p>
<h2>My Battlefield 3 Gaming Machine</h2>
<p><strong>CPU / Processor:</strong><br />
AMD Phenom II X6 1090T Black Edition Thuban 3.2GHz<br />
<a href="http://www.newegg.com/Product/Product.aspx?Item=N82E16819103849" target="_blank">http://www.newegg.com/Product/Produc&#8230;82E16819103849</a></p>
<p><strong>Motherboard:</strong><br />
GIGABYTE GA-990XA-UD3 AM3+ AMD 990X<br />
<a href="http://www.newegg.com/Product/Product.aspx?Item=N82E16813128510" target="_blank">http://www.newegg.com/Product/Produc&#8230;82E16813128510</a></p>
<p><strong>Video Card:</strong><br />
SAPPHIRE 100315L Radeon HD 6850 1GB 256-bit GDDR5<br />
<a href="http://www.newegg.com/Product/Product.aspx?Item=N82E16814102908" target="_blank">http://www.newegg.com/Product/Produc&#8230;82E16814102908</a></p>
<p>with 8GB 1333 DDR3 memory and my current power supply / case which will fit the new components well.</p>
<p>Take the build found here in this article:<br />
<a href="http://pc.mmgn.com/Articles/Building-A-PC-For-Battlefield-3" target="_blank"> http://pc.mmgn.com/Articles/Building-A-PC-For-Battlefield-3</a></p>
<p>This build budget is <span style="color: #ff0000;"><strong>$1000</strong></span>.</p>
<p>With the 3 components I have above I am at $445 with a promotional code (<strong>HARDOCPX817E</strong>) on the processor. This promotion ends <span style="text-decoration: underline;">TODAY</span> &#8211; 8/23/11.</p>
<p>If I added on a Power Supply, HDD, CPU cooler, Case, DVD Drive, and memory:</p>
<p><a href="http://www.newegg.com/Product/Product.aspx?Item=N82E16817341018">OCZ ModXStream Pro 700W</a> &#8211; <span style="color: #ff0000;">$59.99</span> (After rebate) + Free Shipping<br />
<a href="http://www.newegg.com/Product/Product.aspx?Item=N82E16822136073">Western Digital WD5000AAKS 500GB</a> &#8211; <span style="color: #ff0000;">$49.99 + <span style="color: #000000;">Free Shipping</span><br />
<span style="color: #000000;"><a href="http://www.newegg.com/Product/Product.aspx?Item=N82E16835118059">ZALMAN CNPS10X Performa 120mm</a> &#8211; <span style="color: #ff0000;">$40.24</span></span></span> &#8211; Free Shipping<br />
<a href="http://www.newegg.com/Product/Product.aspx?Item=N82E16811147153">Rosewill CHALLENGER Black Gaming ATX Mid Tower Computer Case</a> &#8211; $49.99 + $9.99 Shipping<br />
<a href="http://www.newegg.com/Product/Product.aspx?Item=N82E16827118039">Sony Optiarc CD/DVD Burner Drive</a> &#8211; <span style="color: #ff0000;">$19.99</span><span style="color: #000000;"> + Free Shipping<br />
<a href="http://www.newegg.com/Product/Product.aspx?Item=N82E16820231311">G.SKILL Ripjaws Series 8GB (2 x 4GB)</a> &#8211; <span style="color: #ff0000;">$49.99</span> + Free Shipping</span></p>
<h3><strong>Total</strong>: <span style="text-decoration: underline;"><strong><span style="color: #ff0000;">$749</span></strong></span> (Plus Tax)<br />
Saved: <span style="color: #008000;"><strong>$250!</strong></span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><br />
</span></span></span></h3>
<p>Now whether you are looking to put together a new computer all together or just upgrade some components, this may be helpful to you.</p>
<p>1. <span style="text-decoration: underline;"><strong>Establish your price range</strong></span> &#8211; Sounds simple, but careful &#8211; you may find yourself stretching your boundaries reaching for some luxurious hardware.</p>
<p>2. <span style="text-decoration: underline;"><strong>Look for the deals</strong></span> &#8211; Always look for specials online for websites like <a href="http://newegg.com/">Newegg.com</a> and <a href="http://www.tigerdirect.com/">TigerDirect.com</a>.</p>
<p style="padding-left: 30px;">Promotional codes and coupons can be found online  as well from places like <a href="http://www.retailmenot.com/">RetailMeNot.com</a> or Google. It pays to be patient as well for some upcoming deals for PC components. Check combo deals as well online for Motherboards/CPU&#8217;s or GPU/CPU&#8217;s.</p>
<p>3. <span style="text-decoration: underline;"><strong>Check compatibility</strong></span> -  It is <strong>very</strong> important when picking out computer parts to make sure they are compatible with everything else you are getting or with what you are keeping in your system.</p>
<p style="padding-left: 30px;">With Processors (CPU&#8217;s) you want to make sure your motherboard and CPU are both either Intel or AMD. For example my processor is &#8220;<strong>AMD</strong> Phenom II X6 1090T Black Edition&#8221; and my motherboard is &#8220;GIGABYTE GA-990XA-UD3 <strong>AM3+ AMD</strong> 990X.&#8221; Both are AMD. You also want to make sure that the motherboard accepts the CPU socket type of your processor. My CPU socket type is &#8220;<strong>Socket AM3</strong>&#8221; and if you look under details on my motherboard it says &#8220;CPU Socket Type: <strong>AM3+</strong>.&#8221; Your power supply must also have the power inputs that match your motherboard&#8217;s CPU power input. My motherboard has a 8 pin spot for the CPU and my power supply has that input.</p>
<p style="padding-left: 30px;">You also want to make sure your <span style="text-decoration: underline;">motherboard</span> is compatible with both the <span style="text-decoration: underline;">video card</span> and <span style="text-decoration: underline;">memory</span> you have. Most motherboards have multiple &#8220;PCI Express 2.0 x16&#8243; inputs. You will need at least one for your video card and more than one if you plan on having other components that will use these inputs (sound card, 2nd video card, etc.) The video card must also have the same &#8220;Chipset Manufacturer&#8221; as the motherboard/CPU brand (Intel or AMD). You should also check if features that are available from your video card are possible through your motherboard, such as SLI and CrossfireX. If you are getting a video card for any games (Battlefield 3) make sure it is <strong>DirectX11</strong> under <strong>3D API DirectX</strong>.</p>
<p style="padding-left: 30px;">Most memory online and in stores now is DDR3. If you are upgrading your motherboard you will need to make sure the memory you will have is a compatible speed and type.  If you look at &#8220;Memory Standard&#8221; under details for my motherboard it says &#8220;<strong>DDR3 2000(O.C.)/1866/1600/1333/1066</strong>.&#8221; So it is DDR3 and runs at those speeds &#8211; 2000 is &#8220;Over Clocked.&#8221; My memory is <strong>8GB DDR3 1600MHz</strong> so it is compatible.</p>
<p>Here is my motherboard layout:</p>
<p><img class="alignnone" title="Motherboard Layout" src="http://i671.photobucket.com/albums/vv77/bgallz/motherboard.gif" alt="" width="511" height="382" /></p>
<p>Enjoy building your new PC! Post your builds here or at <a href="http://bfgamerz.com/forum/showthread.php?p=1435#post1435">BFGamerz</a>!</p>
<img src="http://bgallz.org/?ak_action=api_record_view&id=1023&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://bgallz.org/1023/building-battlefield-3-machine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript &amp; PHP Star Rating Script</title>
		<link>http://bgallz.org/988/javascript-php-star-rating-script/</link>
		<comments>http://bgallz.org/988/javascript-php-star-rating-script/#comments</comments>
		<pubDate>Mon, 27 Jun 2011 00:15:42 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[rater]]></category>
		<category><![CDATA[rating]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[star]]></category>

		<guid isPermaLink="false">http://bgallz.org/?p=988</guid>
		<description><![CDATA[I&#8217;ve searched around the interwebs for an ajax star rater and I came across a few different possibilities, all of which looked very good. The top result from google was Nick Stakenburg&#8217;s &#8220;Starbox&#8221; for &#8220;ajax star rater&#8221;. I also found Masuga Web Design&#8217;s Ajax Star Rater and a script from MySandbox to be popular results. However I couldn&#8217;t really seem ...]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve searched around the interwebs for an ajax star rater and I came across a few different possibilities, all of which looked very good. The top result from google was <a href="http://www.nickstakenburg.com/projects/starbox/">Nick Stakenburg&#8217;s &#8220;Starbox&#8221;</a> for &#8220;ajax star rater&#8221;. I also found <a href="http://masugadesign.com/software/unobtrusive-ajax-star-rating-bar/">Masuga Web Design&#8217;s Ajax Star Rater</a> and a script from <a href="http://sandbox.ronggur.com/2009/05/30/jquery-tutorial-simple-ajax-star-rating-with-php/">MySandbox</a> to be popular results. However I couldn&#8217;t really seem to find a PHP / Mysql script that used Javascript for the rater effects. So I decided to make one based off of a script I found:</p>
<p><a href="http://www.reignwaterdesigns.com/ad/tidbits/rateme/">Reign Water Design&#8217;s 5 Star Rating System</a></p>
<p>This was a very nice easy to use Javascript 5 star rating script. All I had to do was make some tweaks to my preference and add on some PHP/Mysql code to submit the rating.</p>
<p><a href="http://bfgamerz.com/resource.php?g=bf-bad-company-2" target="_blank"><strong>See the demo</strong></a> or <a href="http://bgallz.org/scripts/bgallz.org-php-star-rater.rar"><strong>download this script</strong></a>.</p>
<p>To view the PHP source code, images, and everything together you must download this script.</p>
<h2>Javascript:</h2>
<p><strong>Insert the following in the &lt;<em>head</em>&gt; tags of your page:</strong><br />
<div id="wpshdo_1" class="wp-synhighlighter-outer"><div id="wpshdt_1" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_1"></a><a id="wpshat_1" class="wp-synhighlighter-title" href="#codesyntax_1"  onClick="javascript:wpsh_toggleBlock(1)" title="Click to show/hide code block">Javascript Source Code</a></td><td align="right"><a href="#codesyntax_1" onClick="javascript:wpsh_code(1)" title="Show code only"><img border="0" style="border: 0 none" src="http://bgallz.org/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_1" onClick="javascript:wpsh_print(1)" title="Print code"><img border="0" style="border: 0 none" src="http://bgallz.org/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://bgallz.org/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://bgallz.org/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_1" class="wp-synhighlighter-inner" style="display: block;"><pre class="html4strict" style="font-family:monospace;"><span class="sc2">&lt;<a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span>&gt;</span>
function insertParam(key, value)
{
    key = escape(key); value = escape(value);
    var kvp = document.location.search.substr(1).split(&quot;<span class="sc1">&amp;&quot;);</span>
    var i=kvp.length; var x; while(i--)
    {
        x = kvp[i].split(&quot;=&quot;);
        if (x[0]==key)
        {
                x[1] = value;
                kvp[i] = x.join(&quot;=&quot;);
                break;
        }
    }
    if(i<span class="sc2">&lt;0<span class="br0">&#41;</span> <span class="br0">&#123;</span>kvp<span class="br0">&#91;</span>kvp.length<span class="br0">&#93;</span> <span class="sy0">=</span> <span class="br0">&#91;</span>key,<span class="kw3">value</span><span class="br0">&#93;</span>.join<span class="br0">&#40;</span><span class="st0">&quot;=&quot;</span><span class="br0">&#41;</span>;<span class="br0">&#125;</span></span>
<span class="sc2">    <span class="sy0">//</span>this will reload the page, it<span class="st0">'s likely better to store this until finished</span>
<span class="sc2">    document.location.search = kvp.join(&quot;&amp;&quot;);</span>
<span class="sc2">}</span>
<span class="sc2">function alterDisplay(id){</span>
<span class="sc2">	var dropdown = document.getElementById(id);</span>
<span class="sc2">	if(dropdown.style.display == &quot;none&quot;){</span>
<span class="sc2">		dropdown.style.display = &quot;&quot;;</span>
<span class="sc2">	} else {</span>
<span class="sc2">		dropdown.style.display = &quot;none&quot;;</span>
<span class="sc2">	}</span>
<span class="sc2">}</span>
<span class="sc2">&lt;/script&gt;</span></span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span> <span class="kw3">language</span><span class="sy0">=</span><span class="st0">&quot;javascript&quot;</span> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;./scripts/ratingsys.js&quot;</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a>&gt;</span></pre></div></div></p>
<h2>CSS</h2>
<p>You will need to include this in the &lt;<em>head</em>&gt; tags as well either in &lt;<em>style</em>&gt; tags or by &lt;<em>link</em>&gt;:<br />
<div id="wpshdo_2" class="wp-synhighlighter-outer"><div id="wpshdt_2" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_2"></a><a id="wpshat_2" class="wp-synhighlighter-title" href="#codesyntax_2"  onClick="javascript:wpsh_toggleBlock(2)" title="Click to show/hide code block">CSS Styles</a></td><td align="right"><a href="#codesyntax_2" onClick="javascript:wpsh_code(2)" title="Show code only"><img border="0" style="border: 0 none" src="http://bgallz.org/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_2" onClick="javascript:wpsh_print(2)" title="Print code"><img border="0" style="border: 0 none" src="http://bgallz.org/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://bgallz.org/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://bgallz.org/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_2" class="wp-synhighlighter-inner" style="display: block;"><pre class="css" style="font-family:monospace;"><span class="re0">#rateMe</span> <span class="re0">#rate_overlay</span> <span class="br0">&#123;</span>
	<span class="kw1">position</span><span class="sy0">:</span><span class="kw2">absolute</span><span class="sy0">;</span>
	<span class="kw1">display</span><span class="sy0">:</span><span class="kw2">block</span><span class="sy0">;</span>
	<span class="kw1">float</span><span class="sy0">:</span><span class="kw1">left</span><span class="sy0">;</span>
	<span class="kw1">margin</span><span class="sy0">:</span><span class="nu0">0</span><span class="sy0">;</span>
	<span class="kw1">padding</span><span class="sy0">:</span><span class="nu0">0</span><span class="sy0">;</span>
	<span class="kw1">height</span><span class="sy0">:</span><span class="re3">30px</span><span class="sy0">;</span>
	<span class="kw1">width</span><span class="sy0">:</span><span class="kw2">auto</span><span class="sy0">;</span>
	<span class="kw1">background</span><span class="sy0">:</span><span class="re0">#eee</span> <span class="kw2">url</span><span class="br0">&#40;</span><span class="co2">./images/star_overlay.gif</span><span class="br0">&#41;</span> <span class="kw2">repeat-x</span><span class="sy0">;</span>
	<span class="kw1">z-index</span><span class="sy0">:</span><span class="nu0">2</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="re0">#rateStatus</span><span class="br0">&#123;</span><span class="kw1">width</span><span class="sy0">:</span><span class="re3">100px</span><span class="sy0">;</span> <span class="kw1">height</span><span class="sy0">:</span><span class="re3">20px</span><span class="sy0">;</span>margin<span class="sy0">:</span><span class="re3">2px</span> 0 0 <span class="re3">5px</span><span class="sy0">;</span>font<span class="sy0">:</span> <span class="re3">12px</span> <span class="st0">&quot;Trebuchet MS&quot;</span><span class="sy0">,</span> Arial<span class="sy0">,</span> Helvetica<span class="sy0">,</span> <span class="kw2">sans-serif</span><span class="sy0">;</span> <span class="kw1">font-weight</span><span class="sy0">:</span> <span class="kw2">bold</span><span class="br0">&#125;</span>
<span class="re0">#rateMe</span><span class="br0">&#123;</span><span class="kw1">width</span><span class="sy0">:</span><span class="re3">152px</span><span class="sy0">;</span> <span class="kw1">height</span><span class="sy0">:</span><span class="re3">50px</span><span class="sy0">;</span> <span class="kw1">padding</span><span class="sy0">:</span><span class="re3">0px</span><span class="sy0">;</span> <span class="kw1">margin</span><span class="sy0">:</span><span class="re3">0px</span><span class="sy0">;</span> <span class="kw1">vertical-align</span><span class="sy0">:</span><span class="kw1">top</span><span class="sy0">;</span> <span class="kw1">z-index</span><span class="sy0">:</span><span class="kw2">auto</span><span class="br0">&#125;</span>
<span class="re0">#rateMe</span> li<span class="br0">&#123;</span><span class="kw1">float</span><span class="sy0">:</span><span class="kw1">left</span><span class="sy0">;</span>list-style<span class="sy0">:</span><span class="kw2">none</span><span class="sy0">;</span><span class="br0">&#125;</span>
<span class="re0">#rateMe</span> li a<span class="re2">:hover</span><span class="sy0">,</span>
<span class="re0">#rateMe</span> <span class="re1">.on</span><span class="br0">&#123;</span><span class="kw1">background</span><span class="sy0">:</span><span class="kw2">url</span><span class="br0">&#40;</span><span class="co2">./images/star_on.gif</span><span class="br0">&#41;</span> <span class="kw2">no-repeat</span><span class="sy0">;</span><span class="br0">&#125;</span>
<span class="re0">#rateMe</span> a<span class="br0">&#123;</span><span class="kw1">float</span><span class="sy0">:</span><span class="kw1">left</span><span class="sy0">;</span>background<span class="sy0">:</span><span class="kw2">url</span><span class="br0">&#40;</span><span class="co2">./images/star_off.gif</span><span class="br0">&#41;</span> <span class="kw2">no-repeat</span><span class="sy0">;</span>width<span class="sy0">:</span><span class="re3">30px</span><span class="sy0">;</span> <span class="kw1">height</span><span class="sy0">:</span><span class="re3">30px</span><span class="sy0">;</span>cursor<span class="sy0">:</span><span class="kw2">pointer</span><span class="sy0">;</span><span class="br0">&#125;</span>
<span class="re0">#rateMe</span> a<span class="re2">:hover</span><span class="br0">&#123;</span><span class="kw1">background</span><span class="sy0">:</span><span class="kw2">url</span><span class="br0">&#40;</span><span class="co2">./images/star_on.gif</span><span class="br0">&#41;</span> <span class="kw2">no-repeat</span><span class="sy0">;</span><span class="br0">&#125;</span>
<span class="re0">#ratingSaved</span><span class="br0">&#123;</span><span class="kw1">display</span><span class="sy0">:</span><span class="kw2">none</span><span class="sy0">;</span><span class="br0">&#125;</span>
<span class="re1">.saved</span><span class="br0">&#123;</span><span class="kw1">color</span><span class="sy0">:</span><span class="kw2">red</span><span class="sy0">;</span> <span class="br0">&#125;</span></pre></div></div></p>
<p>Basically I took the script that Water&#8217;s made and changed a few things to the css styles, added an overlay for the current rating, and wrote a php script to insert rates and determine the current rating, etc. I also added the Javascript functions <strong>insertParam()</strong> and <strong>alterDisplay()</strong>. You do not need to use this function insertParam() to create the url, you can simply set the &lt;<em>a</em>&gt; tags to something like this:</p>
<div id="wpshdo_3" class="wp-synhighlighter-outer"><div id="wpshdt_3" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_3"></a><a id="wpshat_3" class="wp-synhighlighter-title" href="#codesyntax_3"  onClick="javascript:wpsh_toggleBlock(3)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_3" onClick="javascript:wpsh_code(3)" title="Show code only"><img border="0" style="border: 0 none" src="http://bgallz.org/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_3" onClick="javascript:wpsh_print(3)" title="Print code"><img border="0" style="border: 0 none" src="http://bgallz.org/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://bgallz.org/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://bgallz.org/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_3" class="wp-synhighlighter-inner" style="display: block;"><pre class="html4strict" style="font-family:monospace;"><span class="sc2">&lt;<a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;./index.php?r=1&quot;</span> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;_1&quot;</span> <span class="kw3">title</span><span class="sy0">=</span><span class="st0">&quot;Terrible&quot;</span> <span class="kw3">onmouseover</span><span class="sy0">=</span><span class="st0">&quot;rating(this)&quot;</span> <span class="kw3">onmouseout</span><span class="sy0">=</span><span class="st0">&quot;off(this)&quot;</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a>&gt;</span></pre></div></div>
<p>The Javascript function <strong>alterDisplay()</strong> is used to hide and show the overlay &lt;div&gt; that holds the current rating (if there is one). So when you mouse over the rating bar holder it hides the overlay so you can rate.</p>
<p>The PHP script grabs the information from the Mysql table that you specify in the function. You will need to adjust the following values:</p>
<ul>
<li><strong>$var</strong> &#8211; The column to base your mysql selection off of. Grab all rows where this column equals $id.</li>
<li><strong>$table</strong> &#8211; The table where the ratings are being held.</li>
<li><strong>$star_width</strong> &#8211; Width of the stars, default is 30px.</li>
</ul>
<p><strong><font color="red">You will need to be connected to a MYSQL database before calling the rating bar function.</font></strong></p>
<p>Since the syntax of the function is the following:</p>
<div id="wpshdo_4" class="wp-synhighlighter-outer"><div id="wpshdt_4" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_4"></a><a id="wpshat_4" class="wp-synhighlighter-title" href="#codesyntax_4"  onClick="javascript:wpsh_toggleBlock(4)" title="Click to show/hide code block">Rating Bar Syntax</a></td><td align="right"><a href="#codesyntax_4" onClick="javascript:wpsh_code(4)" title="Show code only"><img border="0" style="border: 0 none" src="http://bgallz.org/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_4" onClick="javascript:wpsh_print(4)" title="Print code"><img border="0" style="border: 0 none" src="http://bgallz.org/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://bgallz.org/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://bgallz.org/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_4" class="wp-synhighlighter-inner" style="display: block;"><pre class="php" style="font-family:monospace;"><span class="kw2">function</span> rating_bar<span class="br0">&#40;</span><span class="re0">$id</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>
<p>You will need to supply the identifier (<strong>$id</strong>) which tells the PHP script which row to grab from the Mysql table.</p>
<p>To display the current rating after it has been rated on &#8211; because Javascript alone is not enough &#8211; I added an overlay &lt;<em>div</em>&gt; which will hold the current rating. This is done by setting the css style of this overlay div to the following:</p>
<div id="wpshdo_5" class="wp-synhighlighter-outer"><div id="wpshdt_5" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_5"></a><a id="wpshat_5" class="wp-synhighlighter-title" href="#codesyntax_5"  onClick="javascript:wpsh_toggleBlock(5)" title="Click to show/hide code block">Rate Overlay CSS Style</a></td><td align="right"><a href="#codesyntax_5" onClick="javascript:wpsh_code(5)" title="Show code only"><img border="0" style="border: 0 none" src="http://bgallz.org/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_5" onClick="javascript:wpsh_print(5)" title="Print code"><img border="0" style="border: 0 none" src="http://bgallz.org/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://bgallz.org/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://bgallz.org/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_5" class="wp-synhighlighter-inner" style="display: block;"><pre class="css" style="font-family:monospace;"><span class="re0">#rateMe</span> <span class="re0">#rate_overlay</span> <span class="br0">&#123;</span>
	<span class="kw1">position</span><span class="sy0">:</span><span class="kw2">absolute</span><span class="sy0">;</span>
	<span class="kw1">display</span><span class="sy0">:</span><span class="kw2">block</span><span class="sy0">;</span>
	<span class="kw1">float</span><span class="sy0">:</span><span class="kw1">left</span><span class="sy0">;</span>
	<span class="kw1">margin</span><span class="sy0">:</span><span class="nu0">0</span><span class="sy0">;</span>
	<span class="kw1">padding</span><span class="sy0">:</span><span class="nu0">0</span><span class="sy0">;</span>
	<span class="kw1">height</span><span class="sy0">:</span><span class="re3">30px</span><span class="sy0">;</span>
	<span class="kw1">width</span><span class="sy0">:</span><span class="kw2">auto</span><span class="sy0">;</span>
	<span class="kw1">background</span><span class="sy0">:</span><span class="re0">#eee</span> <span class="kw2">url</span><span class="br0">&#40;</span><span class="co2">./images/star_overlay.gif</span><span class="br0">&#41;</span> <span class="kw2">repeat-x</span><span class="sy0">;</span>
	<span class="kw1">z-index</span><span class="sy0">:</span><span class="nu0">2</span><span class="sy0">;</span>
<span class="br0">&#125;</span></pre></div></div>
<h3>The <strong>position: aboslute </strong>and <strong>z-index: 2</strong> style attributes make the div lay over top of the <strong><span style="text-decoration: underline;">rateMe</span></strong> div which holds the rater and has a <strong>z-index: 1</strong>.</h3>
<img src="http://bgallz.org/?ak_action=api_record_view&id=988&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://bgallz.org/988/javascript-php-star-rating-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Check if Field Exists in Mysql Table</title>
		<link>http://bgallz.org/977/check-field-exists-mysql-table/</link>
		<comments>http://bgallz.org/977/check-field-exists-mysql-table/#comments</comments>
		<pubDate>Tue, 10 May 2011 17:03:42 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[PHP Functions]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[exists]]></category>
		<category><![CDATA[field]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[table]]></category>

		<guid isPermaLink="false">http://bgallz.org/?p=977</guid>
		<description><![CDATA[Sometimes it is useful to know if a field exists in a mysql table before running a query using that field name, especially when the field name is coming from some kind of user input.
So to do this we use the function mysql_list_fields to grab the fields out of a table and run through them with a for loop until ...]]></description>
			<content:encoded><![CDATA[<p>Sometimes it is useful to know if a field exists in a mysql table before running a query using that field name, especially when the field name is coming from some kind of user input.</p>
<p>So to do this we use the function <strong>mysql_list_fields</strong> to grab the fields out of a table and run through them with a <em>for loop</em> until we find the one we are looking for &#8211; using the function <strong>mysql_field_name</strong>, in which case we return true. If we don&#8217;t find it, the function returns false.</p>
<pre>
&lt;?php

function fieldExists($table,$field)
{

global $db; // DATABASE NAME
// This function is made to have a mysql connection previously established. You can pass the database name globally like this.

$tableFields = mysql_list_fields($db,$table);

for($i=0;$i&lt;mysql_num_fields($tableFields);$i++){
// Run loop through fields.

if(mysql_field_name($tableFields, $i) == $field){
return true;
// We found the field we were looking for. Return true.
}

}
// No return otherwise, false.

}

?&gt;
</pre>
<p>And it&#8217;s that easy!</p>
<img src="http://bgallz.org/?ak_action=api_record_view&id=977&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://bgallz.org/977/check-field-exists-mysql-table/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WHMCS Cron Jobs in cPanel</title>
		<link>http://bgallz.org/873/whmcs-cron-jobs-cpanel/</link>
		<comments>http://bgallz.org/873/whmcs-cron-jobs-cpanel/#comments</comments>
		<pubDate>Thu, 03 Feb 2011 08:46:21 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[cpanel]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[whmcs]]></category>

		<guid isPermaLink="false">http://bgallz.org/?p=873</guid>
		<description><![CDATA[Here we will look at how to set up your WHMCS to run scheduled cron jobs through your cPanel. This allows you to let your clients automatically have their websites and hosting, etc. set up without actually manually doing it. It is an automation feature, which coming from your system&#8217;s cPanel, is availabile in WHMCS. Basically in cPanel you create ...]]></description>
			<content:encoded><![CDATA[<p>Here we will look at how to set up your WHMCS to run scheduled <strong>cron</strong> jobs through your cPanel. This allows you to let your clients automatically have their websites and hosting, etc. set up without actually manually doing it. It is an automation feature, which coming from your system&#8217;s cPanel, is availabile in WHMCS. Basically in cPanel you create a new job under <strong>Cron Jobs</strong> and set it to your <strong>cron.php</strong> in WHMCS to run the automation. These scheduled tasks are very useful for several web applications for businesses or even personal use.</p>
<p><em>So firstly, we need to create a new server in the Servers menu and a product in our Products and Services menu in WHMCS.</em></p>
<p>Assuming you have your WHMCS installed, go to the admin directory &#8220;whmcs/admin/&#8221; and login.</p>
<p>Under <strong>Setup</strong> go to <strong>Servers</strong> (if you don&#8217;t have a server already made) click <strong>Add New Server</strong>. You generally have one main server for the WHMCS you are using, but some larger companies and business/groups have multiple servers &#8211; VPS, Dedicated, etc. Here you need to fill in the information for your server. Below is an image of what mine looks like:</p>
<p><a href="http://bgallz.org/wp-content/uploads/2011/02/serversettings.jpg"><img class="alignnone size-medium wp-image-922" title="serversettings" src="http://bgallz.org/wp-content/uploads/2011/02/serversettings-300x201.jpg" alt="Server Settings" width="300" height="201" /></a></p>
<p>Depending on the software you are using you will need to select it in &#8220;Type&#8221; and input your connection username and password. You will then need to create at least one group for the server you just made. These groups are the different types of accounts that will be setup to run off of this server you select.</p>
<p>Then, under <strong>Setup</strong> go to <strong>Products/Services</strong>. If you don&#8217;t have any groups or products, click the add group/new product links to create a new group and a product inside that group. Set up whatever specific details you want for your new product. If it is hosting of some kind, or just a purchasable service, fill it out to its entirety.</p>
<p>Under the <strong>Module Settings</strong> tab, you will find the fields and inputs for setting up the cPanel and Cron Job properties. Below is an image of what my Product Module Settings looks like:</p>
<p><a href="http://bgallz.org/wp-content/uploads/2011/02/productmodulesettings.jpg"><img class="alignnone size-medium wp-image-921" title="productmodulesettings" src="http://bgallz.org/wp-content/uploads/2011/02/productmodulesettings-300x201.jpg" alt="Product Module Settings" width="300" height="201" /></a></p>
<p>I use cPanel so that is my Module Name. Then you just select the server group you just made for your server.</p>
<p><span style="text-decoration: underline;"><strong>Web Host Manager Settings</strong></span></p>
<p>In your cPanel at the very bottom of the index (homepage) there is a link for your Web Host Manager (WHM). This is the software that cPanel uses for maintaining all of the hosting accounts you have on your server. You must set up your nameservers here that are used in the server you setup in WHMCS. You do this by clicking the &#8220;<strong><strong>B</strong>asic cPanel &amp; WHM Setup</strong>&#8221; link. You must also add the packages here that are the same titles you used when setting up the products and services in the <strong>Module Settings</strong> tab under &#8220;<em>WHM Package Name</em>.&#8221; Your WHMCS will run Cron jobs based off of these values so make sure they are correct.</p>
<p>Finally, we must set the <strong>Cron Jobs Settings</strong> in cPanel.</p>
<p>On your cPanel index page, towards the bottom there is a link for <strong>Cron Jobs</strong>.</p>
<ol>
<li>Enter an email address for support on these accounts affected.</li>
<li>Enter the time interval for this Cron Job to be ran.</li>
<li>The <span style="text-decoration: underline;">Command</span> is the address to your <em>cron.php</em> file in WHMCS.</li>
</ol>
<p>My command line is something like so:</p>
<pre>php -q /home/mysite/public_html/whmcs/admin/cron.php</pre>
<p>This tells cPanel where to get the cron.php script from so it can run the automated jobs for your WHMCS services. Be sure to go through all the settings for the Product/Service you setup. There are a lot of features you may want on or off depending on what the service is.</p>
<p>And that&#8217;s it! Enjoy setting up endless hosting accounts, hands free!</p>
<img src="http://bgallz.org/?ak_action=api_record_view&id=873&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://bgallz.org/873/whmcs-cron-jobs-cpanel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Avoid Duplicate Content Pages</title>
		<link>http://bgallz.org/907/avoid-duplicate-content-pages/</link>
		<comments>http://bgallz.org/907/avoid-duplicate-content-pages/#comments</comments>
		<pubDate>Sun, 30 Jan 2011 22:41:29 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[HTML tags]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[content]]></category>
		<category><![CDATA[duplicate]]></category>
		<category><![CDATA[pages]]></category>

		<guid isPermaLink="false">http://bgallz.org/?p=907</guid>
		<description><![CDATA[Many people do not think about the possibility of duplicate content  pages on their website, when this is very common and easily avoidable.  All it takes is a little HTML in the head tags of the page.
What is a duplicate content page?
Duplicate content is content that is showing up on the Internet by multiple URLs. Another words, a ...]]></description>
			<content:encoded><![CDATA[<p>Many people do not think about the possibility of duplicate content  pages on their website, when this is very common and easily avoidable.  All it takes is a little HTML in the head tags of the page.</p>
<p><span style="text-decoration: underline;"><strong>What is a duplicate content page?</strong></span></p>
<p>Duplicate content is content that is showing up on the Internet by multiple URLs. Another words, a page like <em>aboutus.php</em> might be coming with the same content as <em>aboutus.php?do=send</em>.</p>
<p>This causes some problems with search engines as far as determining  which page the engine should use for query matches, page ranking, use of  meta tags between the two versions, and just which one to include for  their indices.</p>
<p><span style="text-decoration: underline;"><strong>How do you avoid duplicate content?</strong></span></p>
<p>Let&#8217;s say these are your pages that are coming with the same content:</p>
<p><strong>Original source:</strong> <span style="color: blue;"><br />
post.php?id=1</span>.</p>
<p><strong>Duplicate content pages:</strong><br />
<span style="color: blue;">post.php?id=1&amp;lang=en<br />
post.php?id=1&amp;do=login</span></p>
<p>On post.php we can include a &lt;link&gt; tag that will reference to the  original source so Search Engines gather the original correct  information from the server, rather than trying to decide between the  serveral duplicate pages.</p>
<p>Place in the &lt;head&gt; tags of <strong>post.php</strong>:</p>
<pre>
echo&nbsp;&#039;&lt;link&nbsp;href=&quot;./post.php?id=&#039;.((int)$_GET[&#039;id&#039;]).&#039;&quot;&nbsp;rel=&quot;canonical&quot;&nbsp;/&gt;&#039;;
</pre>
<p>This will take the <strong>$id</strong> and put it into the URL as just <strong>post.php?id=$id</strong>.  So any other URL parameters, such as lang=en, or do=login, will not be  read as a duplicate page, but tell search engines to use the content of  just <strong>post.php?id=$id</strong>.</p>
<p>If you do not need to use PHP and you just want the page to load a set content of just <strong>post.php</strong> then you would use the tag like so:</p>
<pre>
&lt;link href=&quot;./post.php&quot; rel=&quot;canonical&quot; /&gt;
</pre>
<p>When using this method, you want to be sure that you are consistent  throughout your website with your canonical URLs. If your canonical url  is like: &#8220;http://www.bgallz.org/&#8221; then you want to use &#8220;www&#8221; in all of  your URL references and tags for the domain.</p>
<p>Now, if you have pages that you do NOT want included in any search  engine queries or crawled by search engine bots, then you want to use a  META tag with &#8220;noindex, nofollow&#8221;.</p>
<p>To block a page from search engine indexes places the following in the &lt;head&gt; tags:</p>
<pre>
<pre>
&lt;meta name=&quot;robots&quot; content=&quot;noindex, nofollow&quot;&gt;
</pre>
<p>Walla!</pre>
<img src="http://bgallz.org/?ak_action=api_record_view&id=907&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://bgallz.org/907/avoid-duplicate-content-pages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTML Div Float Property</title>
		<link>http://bgallz.org/686/html-div-float-property/</link>
		<comments>http://bgallz.org/686/html-div-float-property/#comments</comments>
		<pubDate>Wed, 10 Nov 2010 19:16:25 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[HTML tags]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://bgallz.org/?p=686</guid>
		<description><![CDATA[Using the HTML tag &#8211; &#60;div&#62; and the float style property, you can make designs for your websites. Well, you can make layouts for where design could be. This is a good structural tool in laying out where content will be on your web pages, images, blurbs, etc.
Let&#8217;s say we want a page to look like this:
First I&#8217;m going to ...]]></description>
			<content:encoded><![CDATA[<p>Using the HTML tag &#8211; &lt;div&gt; and the float style property, you can make designs for your websites. Well, you can make layouts for where design could be. This is a good structural tool in laying out where content will be on your web pages, images, blurbs, etc.</p>
<div id="attachment_689" class="wp-caption alignright" style="width: 298px"><a href="http://bgallz.org/wp-content/uploads/2010/11/divfloatlayout1.gif"><img class="size-full wp-image-689" title="divfloatlayout" src="http://bgallz.org/wp-content/uploads/2010/11/divfloatlayout1.gif" alt="Div Float Layout" width="288" height="288" /></a><p class="wp-caption-text">Div Float Layout</p></div>
<p>Let&#8217;s say we want a page to look like this:</p>
<p>First I&#8217;m going to set up the CSS styles we will set our &lt;div&gt;&#8217;s to in the HTML to give this page the right look as far as padding, margins, borders, etc. Once we have all the styles defined we will call them to the DIV tags in our HTML like so: &lt;div class=&#8221;CLASSNAME&#8221;&gt;. Using the right float&#8217;s in the right order will place our DIVs in the right places to make this layout.</p>
<p>This will go in our &lt;head&gt;  tags of the HTML page:</p>
<pre>
html, body, center {
padding: 0px;
margin: 0px;
height: 100%;
}
.header {
padding: 8px;
vertical-align: middle;
height: 80px;
background: #d60000;
}
.banner {
float: left;
border: 0;
vertical-align: middle;
width: 500px;
height: 60px;
}
.ads {
padding: 10px 0px;
float: right;
width: 300px;
height: 60px;
vertical-align: middle;
background: #ffb448;
}
.wrapper { /* Main page holder. */
padding: 10px;
width: 875px;
background: #fff;
height: 100%;
}
.page {
padding: 10px 0px;
width: 630px;
float: left;
height: 100%;
}
.top {
padding: 5px;
height: 40px;
background: #ff7c7c;
margin:0;
}
#boxes {
padding: 5px 0px;
}
.box {
width: 197px;
height: 197px;
padding: 3px;
margin: 3px;
background: #ffddaa;
float: right;
}
.rightside {
float: right;
text-align: center;
height: 100%;
padding: 10px 0px;
}
.nav {
padding: 5px;
background: #ccc;
width: 200px;
height: 100%;
min-height: 600px;
}
.content {
margin: 20px 0px;
width: 600px;
text-align: left;
}
</pre>
<p>Now we have to write the HTML to use these styles appropriately.</p>
<p>Here is our &lt;body&gt; HTML:</p>
<pre>
&lt;body&gt;
&lt;center&gt;
&lt;div class=&quot;wrapper&quot; align=&quot;center&quot;&gt;
&lt;div class=&quot;header&quot;&gt;
&lt;div class=&quot;ads&quot;&gt;Ads Here&lt;/div&gt;
&lt;div class=&quot;banner&quot;&gt;Banner Here&lt;/div&gt;
&lt;/div&gt;
&lt;div align=&quot;center&quot; class=&quot;rightside&quot;&gt;
&lt;div align=&quot;center&quot; class=&quot;nav&quot;&gt;Navigation&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;page&quot;&gt;
&lt;div class=&quot;top&quot;&gt;Content Here&lt;/div&gt;
&lt;div id=&quot;boxes&quot;&gt;
&lt;div class=&quot;box&quot; id=&quot;3&quot;&gt;Box 3&lt;/div&gt;
&lt;div class=&quot;box&quot; id=&quot;2&quot;&gt;Box 2&lt;/div&gt;
&lt;div class=&quot;box&quot; id=&quot;1&quot;&gt;Box 1&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;p&gt;Content Here, lots and lots of content here! Content Here, lots and lots of content here! Content Here, lots and lots of content here! Content Here, lots and lots of content here! Content Here, lots and lots of content here! Content Here, lots and lots of content here! Content Here, lots and lots of content here! Content Here, lots and lots of content here!Content Here, lots and lots of content here!&lt;/p&gt;
&lt;p&gt;Content Here, lots and lots of content here!Content Here, lots and lots of content here!Content Here, lots and lots of content here!Content Here, lots and lots of content here!Content Here, lots and lots of content here!&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/center&gt;
&lt;/body&gt;
</pre>
<p><a title="Div Float Layout" href="http://bgallz.org/html/divfloat.html" target="_blank">Take a look at the HTML in action here!</a></p>
<p>If you notice in the HTML the box&#8217;s are placed in descending order inside the &#8220;boxes&#8221; div ID. Since the box class is set to to the right:</p>
<pre>
.box {
float: right;
}
</pre>
<p>We put the boxes in descending order so that the HTML will read down the page and float the first one to the right, then the next, then the last. So it floats BOX3, then BOX2, then BOX1.</p>
<p>Using the float style property of DIV tags is really useful in making layouts because it does not require any real guidelines to follow as far as where it is on the page. This sounds a little wordy but basically with a combination of float, and position style attributes you can make your DIV&#8217;s go where ever you want.</p>
<img src="http://bgallz.org/?ak_action=api_record_view&id=686&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://bgallz.org/686/html-div-float-property/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Pagination with Mysql</title>
		<link>http://bgallz.org/556/php-pagination-mysql/</link>
		<comments>http://bgallz.org/556/php-pagination-mysql/#comments</comments>
		<pubDate>Thu, 02 Sep 2010 16:52:26 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[pagination]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://bgallz.org/?p=556</guid>
		<description><![CDATA[So you have a Mysql table you want to pull data from, but you don&#8217;t want to flood the page with everything in the table right! So you need some pagination to seperate all the content in the table into easy to open pages.
So let&#8217;s say this is your mysql query:

$sql = mysql_query("SELECT * FROM table1") or die(mysql_error());

So this will ...]]></description>
			<content:encoded><![CDATA[<p>So you have a Mysql table you want to pull data from, but you don&#8217;t want to flood the page with everything in the table right! So you need some pagination to seperate all the content in the table into easy to open pages.</p>
<p><strong>So let&#8217;s say this is your mysql query:</strong></p>
<pre>
$sql = mysql_query("SELECT * FROM table1") or die(mysql_error());
</pre>
<p>So this will grab everything from <em>table1</em>.</p>
<p>If we have a lot of rows in this table this is going to return all of them, so we need to make a pagination for all the rows returned. This requires modifying the query and adding some variables. I like to have the <em>PER_PAGE</em>,<em>OFFSET</em>, and <em>PAGE_NUM</em> variables defined so you can use them globally in every class and function, however you may not want the same values throughout so declare them as you wish.</p>
<p><strong>Here is the header PHP for definitions:</strong></p>
<pre>
// === START Pagination definitions === //
$pgNperPage=15;
$pgNpageNum=1;
if(isset($_GET["p"])){
$pgNpageNum=(int)$_GET["p"];
}
$pgNoffset = ($pgNpageNum - 1) * $pgNperPage;
// definitions
define("SITE_URL","http://mysite.com/",true);
define("PER_PAGE",$pgNperPage,true);
define("OFFSET",$pgNoffset,true);
define("PAGE_NUM",$pgNpageNum,true);
// === END Pagination definitions === //
</pre>
<p>So we have to modify the query we use in <em>$sql</em> to include a limit with the offset and per page values used. I have made a pagination function which will do everything for me. We&#8217;ll pass the query along with some parameters through this function to output the new query and the pagination HTML.</p>
<p><strong>Here is the function syntax:</strong></p>
<pre>
pagination($query,$pageNum,$perpage,$sortable,$cat="",$sort="",$headers="",$pageL="");
</pre>
<p><span style="text-decoration: underline;"><strong>Function Paremeters:</strong></span></p>
<ul>
<li><span style="text-decoration: underline;">$query</span> &#8211; The original query to use for the Mysql. i.e. &#8220;SELECT * FROM table1&#8243;. (No ORDER BY or LIMIT).</li>
<li><span style="text-decoration: underline;">$pageNum</span> &#8211; Current page number.</li>
<li><span style="text-decoration: underline;">$perpage</span> &#8211; Per page integer value.</li>
<li><span style="text-decoration: underline;">$sortable</span> &#8211; Array of sortable fields in mysql table to order the results by.</li>
<li><span style="text-decoration: underline;">$cat</span> &#8211; What is being paginated. i.e. (Users, videos, comments, etc.) [<span style="color: #ff0000;">Optional</span>]</li>
<li><span style="text-decoration: underline;">$sort</span> &#8211; Field in Mysql table to sort it by. Default in the function definition is &#8220;timestamp&#8221; &#8211; usually used for date. [<span style="color: #ff0000;">Optional</span>]</li>
<li><span style="text-decoration: underline;">$headers</span> &#8211; Additional URL headers besides the sort and page number. i.e. &#8220;&amp;g=bf-2142&#8243; (Start with <span style="color: #008000;"><strong>&amp;</strong></span> not <span style="color: #800000;"><del>?</del></span>) [<span style="color: #ff0000;">Optional</span>]</li>
<li><span style="text-decoration: underline;">$pageL</span> &#8211; Pagination letter. Useful if you have multiple paginations on one page. i.e. &#8220;cp&#8221;. (Default is p.) [<span style="color: #ff0000;">Optional</span>]</li>
</ul>
<p><strong>Here is the pagination function definition:<br />
</strong></p>
<pre>
function pagination($query,$pageNum,$perpage,$sortable,$cat="",$sort="",$headers="",$pageL=""){
$pagination = array();
$paginationDetails = "";
$adjacents = 3;
if(!$perpage){
$perpage = 15; // default
}
if($cat){
$cat = " ".$cat."";
}
$pageNum = (int)$pageNum;
if(!$pageNum){
$pageNum=1;
}
if(!$pageL){
$pageL="p";
}
$pgNoffset = ($pageNum - 1) * $perpage;

if(isset($_GET['dsc']) &amp;&amp; $_GET['dsc'] != ""){
$dsc = "DESC";
$urldsc = "&amp;dsc=1";
} else {
$dsc = "";
$urldsc = "";
}
if(is_array($sortable)){
if(in_array($sort,$sortable)){
$sort = trim($sort);
} else {
$sort = "";
}
}
if($sort){
$order_by = "ORDER BY ".$sort." ".$dsc."";
} else {
$order_by = "";
}
$limit = "LIMIT ".$pgNoffset.",".$perpage."";
$queryNew = $query.' '.$order_by.' '.$limit;
$pagination[] = $queryNew;
if(strpos($_SERVER["REQUEST_URI"],"?")){
$pos = strpos($_SERVER["REQUEST_URI"],"?");
} else {
$pos = strlen($_SERVER["REQUEST_URI"]);
}
$pageURL = substr($_SERVER["REQUEST_URI"],0,$pos);

$pageURL .= "?sort=".$sort."";
$pageURL .= "&amp;dsc=".$dsc."";
$pageURL .= $headers;

$sql = mysql_query($queryNew) or die(mysql_error());
$count = mysql_num_rows($sql);
if($count &gt; 0){
$totalQuery = mysql_query($query) or die(mysql_error());
$totalCount = mysql_num_rows($totalQuery);
$total = ceil($totalCount / $perpage);
$pm1 = $total - 1;
$paginationDetails .= '&lt;p&gt;
&lt;table width="100%" align="center" border="0" cellpadding="2" cellspacing="1"&gt;&lt;tr&gt;
&lt;td align="left"&gt;&lt;div&gt;Displaying '.$count.' of '.$totalCount.$cat.'.&lt;/div&gt;&lt;/td&gt;
&lt;td align="right"&gt;
&lt;table border="0" align="right" cellpadding="2" cellspacing="1" width="100%"&gt;&lt;tr&gt;
&lt;td&gt;Page '.$pageNum.' of '.$total.'&lt;/td&gt;';
if($pageNum &gt; 1){
// previous button
$paginationDetails .= '&lt;td align="center"&gt;&lt;a href="'.$pageURL.'&amp;'.$pageL.'='.(PAGE_NUM - 1).'"&gt;&amp;lsaquo; Prev&lt;/a&gt;&lt;/td&gt;';
}
// conditionals for breaking up the pages
if($total &lt; 7 + ($adjacents*2)){
// not enought to break up
for($page=1;$page&lt;=$total;$page++){
if($page == $pageNum){
$paginationDetails .= '&lt;td align="center"&gt;'.$page.'&lt;/td&gt;';
} else {
$paginationDetails .= '&lt;td align="center"&gt;&lt;a href="'.$pageURL.'&amp;'.$pageL.'='.$page.'"&gt;'.$page.'&lt;/a&gt;&lt;/td&gt;';
}
}
}
else if($total &gt; 5 + ($adjacents*2)){
// enought to hide some
if($pageNum &lt; 1 + ($adjacents*2)){
// hide later pages
for($page=1;$page&lt;5+($adjacents*2);$page++){
if($page == $pageNum){
$paginationDetails .= '&lt;td align="center"&gt;'.$page.'&lt;/td&gt;';
} else {
$paginationDetails .= '&lt;td align="center"&gt;&lt;a href="'.$pageURL.'&amp;'.$pageL.'='.$page.'"&gt;'.$page.'&lt;/a&gt;&lt;/td&gt;';
}
}
$paginationDetails .= '&lt;td align="center"&gt;...&lt;/td&gt;';
$paginationDetails .= '&lt;td align="center"&gt;&lt;a href="'.$pageURL.'&amp;'.$pageL.'='.$pm1.'"&gt;'.$pm1.'&lt;/a&gt;&lt;/td&gt;';
$paginationDetails .= '&lt;td align="center"&gt;&lt;a href="'.$pageURL.'&amp;'.$pageL.'='.$total.'"&gt;'.$total.'&lt;/a&gt;&lt;/td&gt;';
}
else if($total - ($adjacents*2) &gt; $pageNum &amp;&amp; $pageNum &gt; ($adjacents * 2)){
// in middle, hide little front and back
$paginationDetails .= '&lt;td align="center"&gt;&lt;a href="'.$pageURL.'&amp;'.$pageL.'=1"&gt;1&lt;/a&gt;&lt;/td&gt;';
$paginationDetails .= '&lt;td align="center"&gt;&lt;a href="'.$pageURL.'&amp;'.$pageL.'=2"&gt;2&lt;/a&gt;&lt;/td&gt;';
$paginationDetails .= '&lt;td align="center"&gt;...&lt;/td&gt;';
for($page=($pageNum - $adjacents);$page&lt;=($pageNum + $adjacents);$page++){
if($page == $pageNum){
$paginationDetails .= '&lt;td align="center"&gt;'.$page.'&lt;/td&gt;';
} else {
$paginationDetails .= '&lt;td align="center"&gt;&lt;a href="'.$pageURL.'&amp;'.$pageL.'='.$page.'"&gt;'.$page.'&lt;/a&gt;&lt;/td&gt;';
}
}
$paginationDetails .= '&lt;td align="center"&gt;...&lt;/td&gt;';
$paginationDetails .= '&lt;td align="center"&gt;&lt;a href="'.$page.'&amp;'.$pageL.'='.$pm1.'"&gt;'.$pm1.'&lt;/a&gt;&lt;/td&gt;';
$paginationDetails .= '&lt;td align="center"&gt;&lt;a href="'.$page.'&amp;'.$pageL.'='.$total.'"&gt;'.$total.'&lt;/a&gt;&lt;/td&gt;';
}
else {
// close to end, hide early pages
$paginationDetails .= '&lt;td align="center"&gt;&lt;a href="'.$pageURL.'&amp;'.$pageL.'=1"&gt;1&lt;/a&gt;&lt;/td&gt;';
$paginationDetails .= '&lt;td align="center"&gt;&lt;a href="'.$pageURL.'&amp;'.$pageL.'=2"&gt;2&lt;/a&gt;&lt;/td&gt;';
$paginationDetails .= '&lt;td align="center"&gt;...&lt;/td&gt;';
for($page=$total - (3 +($adjacents*2));$page&lt;=$total;$page++){
if($page == $pageNum){
$paginationDetails .= '&lt;td align="center"&gt;'.$page.'&lt;/td&gt;';
} else {
$paginationDetails .= '&lt;td align="center"&gt;&lt;a href="'.$pageURL.'&amp;'.$pageL.'='.$page.'"&gt;'.$page.'&lt;/a&gt;&lt;/td&gt;';
}
}
}
}

if($pageNum &lt; $total){
$paginationDetails .= '&lt;td align="center"&gt;&lt;a href="'.$pageURL.'&amp;'.$pageL.'='.($pageNum + 1).'"&gt;Next &amp;rsaquo;&lt;/a&gt;&lt;/td&gt;';
}
$paginationDetails .= '&lt;/tr&gt;&lt;/table&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/p&gt;';
$pagination[] = $paginationDetails;
}
return $pagination;
}
</pre>
<p>Now we just need to include the HTML and CSS classes for the pagination so viewers can navigate through the pages returned from this query.</p>
<p><strong>Pagination CSS:</strong></p>
<pre>
&lt;!--
.pagination {
margin: 0px;
background-color: #eaeaea;
padding: 0px;
}
.a_page {
margin: 0px;
padding: 2px;
color: #343434;
background-color: #f5f5f5;
font-size: 11px;
font-family: tahoma;
}
.a_page a {
color: #000;
text-decoration: underline;
}
.page_selected {
background-color: #ffffff;
color: #000;
font-weight: bold;
padding: 1px;
border: 1px solid #d9dbdc;
font-size: 11px;
font-family: tahoma;
}
.page_selected a {
color: #000;
}
--&gt;.pagination,.pagination div {
background-color: #eee;
font: 11px tahoma;
border: 1px solid #ccc;
text-align: left;
}
.a_td {
color: #343434;
background-color: #fff;
font-size: 11px;
font-family: tahoma;
}
.a_page {
color: #343434;
background-color: #fff;
font-size: 11px;
font-family: tahoma;
padding:0px;
}
.a_page:hover {
background-color: #eee;
}
.a_page a {
display:block;
padding:2px;
color: #333;
text-decoration: none;
}
.page_selected {
background-color: #333;
color: #fff;
font-weight: bold;
font-size: 11px;
font-family: tahoma;
}
.page_selected a {
color: #000;
}
</pre>
<p>Now we have the function included on our page along with the necessary CSS styles. Now we can call the function and echo the contents of the returned array. The function <strong>pagination</strong> returns an array like so: <em>pagination = [newMysqlQuery, paginationHTML]</em>.<strong></strong></p>
<p><strong>So let&#8217;s say this was our function for downloads:<br />
</strong></p>
<pre>
function downloads($g){
$g=mysql_real_escape_string($g); // Game
$validSorts = array("title","catType","dl_count","timestamp"); // Sorts
if(isset($_GET['sort']) &amp;&amp; in_array($_GET['sort'],$validSorts)){
$sort = mysql_real_escape_string($_GET['sort']);
} else {
$sort = 'timestamp'; // default sort used.
}
if(isset($_GET['dsc'])){
$desc = "DESC";
} else {
$desc = "";
}
if(isset($_GET['p'])){
$page = (int)$_GET['p'];
} else {
$page = 1;
}
$query = "SELECT * FROM downloads WHERE gameCat = '$g'";
$pagination = pagination($query,$page,15,$validSorts,"downloads",$sort,"&amp;g=".$g.""); // Call the function.
$sql = mysql_query($pagination[0]) or die(mysql_error()); // $pagination[0] = new query.
$count = mysql_num_rows($sql);
}
</pre>
<p>Now we have called the pagination function with some variables for displaying our downloads. Along with printing the pagination HTML you could display the rows with the new Mysql query that the function returns.</p>
<p><a title="Display Mysql Rows from Table" href="http://bgallz.org/82/mysql-rows-from-a-table/">See how to display Mysql Rows here!</a></p>
<p><strong>For this example we will simply echo the pagination HTML:</strong></p>
<pre>
echo $pagination[1];
</pre>
<p><strong>Check this function out LIVE here:</strong></p>
<p><a title="Members" href="http://bfgamerz.com/members.php">http://bfgamerz.com/members.php</a></p>
<img src="http://bgallz.org/?ak_action=api_record_view&id=556&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://bgallz.org/556/php-pagination-mysql/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>PHP Upload and Resize Image</title>
		<link>http://bgallz.org/502/php-upload-resize-image/</link>
		<comments>http://bgallz.org/502/php-upload-resize-image/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 17:21:42 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[height]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[resize]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[upload]]></category>
		<category><![CDATA[width]]></category>

		<guid isPermaLink="false">http://bgallz.org/?p=502</guid>
		<description><![CDATA[Many times when you upload a image somewhere you want to resize it to different dimensions based off of a maximum width or height. Here is a simple script that does this for you, using a HTML form and a PHP script. We start with the PHP script that will run if our $_GET['do'] is set to &#8220;upload.&#8221; Then we ...]]></description>
			<content:encoded><![CDATA[<p>Many times when you upload a image somewhere you want to resize it to different dimensions based off of a maximum width or height. Here is a simple script that does this for you, using a HTML form and a PHP script. We start with the PHP script that will run if our <em>$_GET['do']</em> is set to &#8220;upload.&#8221; Then we include the HTML form that has three inputs (max width, max height, image file).</p>
<p><a title="Upload and Resize Demo" href="http://bgallz.org/scripts/upload-resize-image/" target="_blank"><strong>Use the Upload and Resize Demo Here!</strong></a></p>
<p><a href="http://bgallz.org/scripts/upload-resize-image/bgallz.org-Upload-and-Resize-Image-Script.rar"><strong>Download This Script!</strong></a></p>
<p>Here is the PHP:</p>
<div id="wpshdo_6" class="wp-synhighlighter-outer"><div id="wpshdt_6" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_6"></a><a id="wpshat_6" class="wp-synhighlighter-title" href="#codesyntax_6"  onClick="javascript:wpsh_toggleBlock(6)" title="Click to show/hide code block">Upload and Resize PHP Code</a></td><td align="right"><a href="#codesyntax_6" onClick="javascript:wpsh_code(6)" title="Show code only"><img border="0" style="border: 0 none" src="http://bgallz.org/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_6" onClick="javascript:wpsh_print(6)" title="Print code"><img border="0" style="border: 0 none" src="http://bgallz.org/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://bgallz.org/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://bgallz.org/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_6" class="wp-synhighlighter-inner" style="display: block;"><pre class="php" style="font-family:monospace;"><span class="kw2">&lt;?php</span>
<span class="co1">// index.php</span>
<span class="kw2">function</span> generate_resized_image<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
<span class="re0">$max_dimension</span> <span class="sy0">=</span> <span class="nu0">800</span><span class="sy0">;</span> <span class="co1">// Max new width or height, can not exceed this value.</span>
<span class="re0">$dir</span> <span class="sy0">=</span> <span class="st0">&quot;./images/&quot;</span><span class="sy0">;</span> <span class="co1">// Directory to save resized image. (Include a trailing slash - /)</span>
<span class="co1">// Collect the post variables.</span>
<span class="re0">$postvars</span> <span class="sy0">=</span> <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span>
<span class="st0">&quot;image&quot;</span>    <span class="sy0">=&gt;</span> <a href="http://www.php.net/trim"><span class="kw3">trim</span></a><span class="br0">&#40;</span><span class="re0">$_FILES</span><span class="br0">&#91;</span><span class="st0">&quot;image&quot;</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st0">&quot;name&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">,</span>
<span class="st0">&quot;image_tmp&quot;</span>    <span class="sy0">=&gt;</span> <span class="re0">$_FILES</span><span class="br0">&#91;</span><span class="st0">&quot;image&quot;</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st0">&quot;tmp_name&quot;</span><span class="br0">&#93;</span><span class="sy0">,</span>
<span class="st0">&quot;image_size&quot;</span>    <span class="sy0">=&gt;</span> <span class="br0">&#40;</span>int<span class="br0">&#41;</span><span class="re0">$_FILES</span><span class="br0">&#91;</span><span class="st0">&quot;image&quot;</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st0">&quot;size&quot;</span><span class="br0">&#93;</span><span class="sy0">,</span>
<span class="st0">&quot;image_max_width&quot;</span>    <span class="sy0">=&gt;</span> <span class="br0">&#40;</span>int<span class="br0">&#41;</span><span class="re0">$_POST</span><span class="br0">&#91;</span><span class="st0">&quot;image_max_width&quot;</span><span class="br0">&#93;</span><span class="sy0">,</span>
<span class="st0">&quot;image_max_height&quot;</span>   <span class="sy0">=&gt;</span> <span class="br0">&#40;</span>int<span class="br0">&#41;</span><span class="re0">$_POST</span><span class="br0">&#91;</span><span class="st0">&quot;image_max_height&quot;</span><span class="br0">&#93;</span>
<span class="br0">&#41;</span><span class="sy0">;</span>
<span class="co1">// Array of valid extensions.</span>
<span class="re0">$valid_exts</span> <span class="sy0">=</span> <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="st0">&quot;jpg&quot;</span><span class="sy0">,</span><span class="st0">&quot;jpeg&quot;</span><span class="sy0">,</span><span class="st0">&quot;gif&quot;</span><span class="sy0">,</span><span class="st0">&quot;png&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="co1">// Select the extension from the file.</span>
<span class="re0">$ext</span> <span class="sy0">=</span> <a href="http://www.php.net/end"><span class="kw3">end</span></a><span class="br0">&#40;</span><a href="http://www.php.net/explode"><span class="kw3">explode</span></a><span class="br0">&#40;</span><span class="st0">&quot;.&quot;</span><span class="sy0">,</span><a href="http://www.php.net/strtolower"><span class="kw3">strtolower</span></a><span class="br0">&#40;</span><a href="http://www.php.net/trim"><span class="kw3">trim</span></a><span class="br0">&#40;</span><span class="re0">$_FILES</span><span class="br0">&#91;</span><span class="st0">&quot;image&quot;</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st0">&quot;name&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="co1">// Check not larger than 175kb.</span>
<span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$postvars</span><span class="br0">&#91;</span><span class="st0">&quot;image_size&quot;</span><span class="br0">&#93;</span> <span class="sy0">&lt;=</span> <span class="nu0">179200</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
<span class="co1">// Check is valid extension.</span>
<span class="kw1">if</span><span class="br0">&#40;</span><a href="http://www.php.net/in_array"><span class="kw3">in_array</span></a><span class="br0">&#40;</span><span class="re0">$ext</span><span class="sy0">,</span><span class="re0">$valid_exts</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
<span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$ext</span> <span class="sy0">==</span> <span class="st0">&quot;jpg&quot;</span> <span class="sy0">||</span> <span class="re0">$ext</span> <span class="sy0">==</span> <span class="st0">&quot;jpeg&quot;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
<span class="re0">$image</span> <span class="sy0">=</span> <a href="http://www.php.net/imagecreatefromjpeg"><span class="kw3">imagecreatefromjpeg</span></a><span class="br0">&#40;</span><span class="re0">$postvars</span><span class="br0">&#91;</span><span class="st0">&quot;image_tmp&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="kw1">else</span> <span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$ext</span> <span class="sy0">==</span> <span class="st0">&quot;gif&quot;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
<span class="re0">$image</span> <span class="sy0">=</span> <a href="http://www.php.net/imagecreatefromgif"><span class="kw3">imagecreatefromgif</span></a><span class="br0">&#40;</span><span class="re0">$postvars</span><span class="br0">&#91;</span><span class="st0">&quot;image_tmp&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="kw1">else</span> <span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$ext</span> <span class="sy0">==</span> <span class="st0">&quot;png&quot;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
<span class="re0">$image</span> <span class="sy0">=</span> <a href="http://www.php.net/imagecreatefrompng"><span class="kw3">imagecreatefrompng</span></a><span class="br0">&#40;</span><span class="re0">$postvars</span><span class="br0">&#91;</span><span class="st0">&quot;image_tmp&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="co1">// Grab the width and height of the image.</span>
<a href="http://www.php.net/list"><span class="kw3">list</span></a><span class="br0">&#40;</span><span class="re0">$width</span><span class="sy0">,</span><span class="re0">$height</span><span class="br0">&#41;</span> <span class="sy0">=</span> <a href="http://www.php.net/getimagesize"><span class="kw3">getimagesize</span></a><span class="br0">&#40;</span><span class="re0">$postvars</span><span class="br0">&#91;</span><span class="st0">&quot;image_tmp&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="co1">// If the max width input is greater than max height we base the new image off of that, otherwise we</span>
<span class="co1">// use the max height input.</span>
<span class="co1">// We get the other dimension by multiplying the quotient of the new width or height divided by</span>
<span class="co1">// the old width or height.</span>
<span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$postvars</span><span class="br0">&#91;</span><span class="st0">&quot;image_max_width&quot;</span><span class="br0">&#93;</span> <span class="sy0">&gt;</span> <span class="re0">$postvars</span><span class="br0">&#91;</span><span class="st0">&quot;image_max_height&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
<span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$postvars</span><span class="br0">&#91;</span><span class="st0">&quot;image_max_width&quot;</span><span class="br0">&#93;</span> <span class="sy0">&gt;</span> <span class="re0">$max_dimension</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
<span class="re0">$newwidth</span> <span class="sy0">=</span> <span class="re0">$max_dimension</span><span class="sy0">;</span>
<span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span>
<span class="re0">$newwidth</span> <span class="sy0">=</span> <span class="re0">$postvars</span><span class="br0">&#91;</span><span class="st0">&quot;image_max_width&quot;</span><span class="br0">&#93;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="re0">$newheight</span> <span class="sy0">=</span> <span class="br0">&#40;</span><span class="re0">$newwidth</span> <span class="sy0">/</span> <span class="re0">$width</span><span class="br0">&#41;</span> <span class="sy0">*</span> <span class="re0">$height</span><span class="sy0">;</span>
<span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span>
<span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$postvars</span><span class="br0">&#91;</span><span class="st0">&quot;image_max_height&quot;</span><span class="br0">&#93;</span> <span class="sy0">&gt;</span> <span class="re0">$max_dimension</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
<span class="re0">$newheight</span> <span class="sy0">=</span> <span class="re0">$max_dimension</span><span class="sy0">;</span>
<span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span>
<span class="re0">$newheight</span> <span class="sy0">=</span> <span class="re0">$postvars</span><span class="br0">&#91;</span><span class="st0">&quot;image_max_height&quot;</span><span class="br0">&#93;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="re0">$newwidth</span> <span class="sy0">=</span> <span class="br0">&#40;</span><span class="re0">$newheight</span> <span class="sy0">/</span> <span class="re0">$height</span><span class="br0">&#41;</span> <span class="sy0">*</span> <span class="re0">$width</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="co1">// Create temporary image file.</span>
<span class="re0">$tmp</span> <span class="sy0">=</span> <a href="http://www.php.net/imagecreatetruecolor"><span class="kw3">imagecreatetruecolor</span></a><span class="br0">&#40;</span><span class="re0">$newwidth</span><span class="sy0">,</span><span class="re0">$newheight</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="co1">// Copy the image to one with the new width and height.</span>
<a href="http://www.php.net/imagecopyresampled"><span class="kw3">imagecopyresampled</span></a><span class="br0">&#40;</span><span class="re0">$tmp</span><span class="sy0">,</span><span class="re0">$image</span><span class="sy0">,</span>0<span class="sy0">,</span>0<span class="sy0">,</span>0<span class="sy0">,</span>0<span class="sy0">,</span><span class="re0">$newwidth</span><span class="sy0">,</span><span class="re0">$newheight</span><span class="sy0">,</span><span class="re0">$width</span><span class="sy0">,</span><span class="re0">$height</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="co1">// Create random 4 digit number for filename.</span>
<span class="re0">$rand</span> <span class="sy0">=</span> <a href="http://www.php.net/rand"><span class="kw3">rand</span></a><span class="br0">&#40;</span>1000<span class="sy0">,</span>9999<span class="br0">&#41;</span><span class="sy0">;</span>
<span class="re0">$filename</span> <span class="sy0">=</span> <span class="re0">$dir</span><span class="sy0">.</span><span class="re0">$rand</span><span class="sy0">.</span><span class="re0">$postvars</span><span class="br0">&#91;</span><span class="st0">&quot;image&quot;</span><span class="br0">&#93;</span><span class="sy0">;</span>
<span class="co1">// Create image file with 100% quality.</span>
<a href="http://www.php.net/imagejpeg"><span class="kw3">imagejpeg</span></a><span class="br0">&#40;</span><span class="re0">$tmp</span><span class="sy0">,</span><span class="re0">$filename</span><span class="sy0">,</span>100<span class="br0">&#41;</span><span class="sy0">;</span>
<span class="kw1">return</span> <span class="st0">&quot;&lt;strong&gt;Image Preview:&lt;/strong&gt;&lt;br/&gt;
&lt;img src=<span class="es1">\&quot;</span>&quot;</span><span class="sy0">.</span><span class="re0">$filename</span><span class="sy0">.</span><span class="st0">&quot;<span class="es1">\&quot;</span> border=<span class="es1">\&quot;</span>0<span class="es1">\&quot;</span> title=<span class="es1">\&quot;</span>Resized  Image Preview<span class="es1">\&quot;</span> style=<span class="es1">\&quot;</span>padding: 4px 0px 4px 0px;background-color:#e0e0e0<span class="es1">\&quot;</span> /&gt;&lt;br/&gt;
Resized image successfully generated. &lt;a href=<span class="es1">\&quot;</span>&quot;</span><span class="sy0">.</span><span class="re0">$filename</span><span class="sy0">.</span><span class="st0">&quot;<span class="es1">\&quot;</span> target=<span class="es1">\&quot;</span>_blank<span class="es1">\&quot;</span> name=<span class="es1">\&quot;</span>Download your resized image now!<span class="es1">\&quot;</span>&gt;Click here to download your image.&lt;/a&gt;&quot;</span><span class="sy0">;</span>
<a href="http://www.php.net/imagedestroy"><span class="kw3">imagedestroy</span></a><span class="br0">&#40;</span><span class="re0">$image</span><span class="br0">&#41;</span><span class="sy0">;</span>
<a href="http://www.php.net/imagedestroy"><span class="kw3">imagedestroy</span></a><span class="br0">&#40;</span><span class="re0">$tmp</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span>
<span class="kw1">return</span> <span class="st0">&quot;File size too large. Max allowed file size is 175kb.&quot;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span>
<span class="kw1">return</span> <span class="st0">&quot;Invalid file type. You must upload an image file. (jpg, jpeg, gif, png).&quot;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="br0">&#125;</span>
<span class="kw1">if</span><span class="br0">&#40;</span><a href="http://www.php.net/isset"><span class="kw3">isset</span></a><span class="br0">&#40;</span><span class="re0">$_GET</span><span class="br0">&#91;</span><span class="st0">&quot;do&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
<span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$_GET</span><span class="br0">&#91;</span><span class="st0">&quot;do&quot;</span><span class="br0">&#93;</span> <span class="sy0">==</span> <span class="st0">&quot;upload&quot;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
<span class="re0">$upload_and_resize</span> <span class="sy0">=</span> generate_resized_image<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span>
<span class="re0">$upload_and_resize</span> <span class="sy0">=</span> <span class="st0">&quot;&quot;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span>
<span class="re0">$upload_and_resize</span> <span class="sy0">=</span> <span class="st0">&quot;&quot;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="sy1">?&gt;</span></pre></div></div>
<p>Here is the HTML:</p>
<div id="wpshdo_7" class="wp-synhighlighter-outer"><div id="wpshdt_7" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_7"></a><a id="wpshat_7" class="wp-synhighlighter-title" href="#codesyntax_7"  onClick="javascript:wpsh_toggleBlock(7)" title="Click to show/hide code block">HTML Form</a></td><td align="right"><a href="#codesyntax_7" onClick="javascript:wpsh_code(7)" title="Show code only"><img border="0" style="border: 0 none" src="http://bgallz.org/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_7" onClick="javascript:wpsh_print(7)" title="Print code"><img border="0" style="border: 0 none" src="http://bgallz.org/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://bgallz.org/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://bgallz.org/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_7" class="wp-synhighlighter-inner" style="display: block;"><pre class="html4strict" style="font-family:monospace;"><span class="sc2">&lt;<a href="http://december.com/html/4/element/form.html"><span class="kw2">form</span></a> <span class="kw3">action</span><span class="sy0">=</span><span class="st0">&quot;./index.php?do=upload&quot;</span> <span class="kw3">method</span><span class="sy0">=</span><span class="st0">&quot;post&quot;</span> <span class="kw3">enctype</span><span class="sy0">=</span><span class="st0">&quot;multipart/form-data&quot;</span>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/table.html"><span class="kw2">table</span></a> <span class="kw3">width</span><span class="sy0">=</span><span class="st0">&quot;100%&quot;</span> <span class="kw3">align</span><span class="sy0">=</span><span class="st0">&quot;center&quot;</span> <span class="kw3">border</span><span class="sy0">=</span><span class="st0">&quot;0&quot;</span> <span class="kw3">cellpadding</span><span class="sy0">=</span><span class="st0">&quot;2&quot;</span> <span class="kw3">cellspacing</span><span class="sy0">=</span><span class="st0">&quot;0&quot;</span>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/tr.html"><span class="kw2">tr</span></a>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/td.html"><span class="kw2">td</span></a> <span class="kw3">align</span><span class="sy0">=</span><span class="st0">&quot;left&quot;</span> <span class="kw3">width</span><span class="sy0">=</span><span class="st0">&quot;100&quot;</span>&gt;</span>
Max Width:<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/td.html"><span class="kw2">td</span></a>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/td.html"><span class="kw2">td</span></a> <span class="kw3">align</span><span class="sy0">=</span><span class="st0">&quot;left&quot;</span>&gt;&lt;<a href="http://december.com/html/4/element/input.html"><span class="kw2">input</span></a> <span class="kw3">name</span><span class="sy0">=</span><span class="st0">&quot;image_max_width&quot;</span> <span class="kw3">style</span><span class="sy0">=</span><span class="st0">&quot;width: 120px&quot;</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text&quot;</span> <span class="kw3">maxlength</span><span class="sy0">=</span><span class="st0">&quot;4&quot;</span> <span class="sy0">/</span>&gt;</span> px.<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/td.html"><span class="kw2">td</span></a>&gt;</span>
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/tr.html"><span class="kw2">tr</span></a>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/tr.html"><span class="kw2">tr</span></a>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/td.html"><span class="kw2">td</span></a> <span class="kw3">align</span><span class="sy0">=</span><span class="st0">&quot;left&quot;</span>&gt;</span>
Max Height:<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/td.html"><span class="kw2">td</span></a>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/td.html"><span class="kw2">td</span></a> <span class="kw3">align</span><span class="sy0">=</span><span class="st0">&quot;left&quot;</span>&gt;&lt;<a href="http://december.com/html/4/element/input.html"><span class="kw2">input</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text&quot;</span> <span class="kw3">name</span><span class="sy0">=</span><span class="st0">&quot;image_max_height&quot;</span> <span class="kw3">style</span><span class="sy0">=</span><span class="st0">&quot;width: 120px&quot;</span> <span class="kw3">maxlength</span><span class="sy0">=</span><span class="st0">&quot;4&quot;</span> <span class="sy0">/</span>&gt;</span> px.<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/td.html"><span class="kw2">td</span></a>&gt;</span>
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/tr.html"><span class="kw2">tr</span></a>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/tr.html"><span class="kw2">tr</span></a>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/td.html"><span class="kw2">td</span></a> <span class="kw3">align</span><span class="sy0">=</span><span class="st0">&quot;left&quot;</span>&gt;</span>
Image:<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/td.html"><span class="kw2">td</span></a>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/td.html"><span class="kw2">td</span></a> <span class="kw3">align</span><span class="sy0">=</span><span class="st0">&quot;left&quot;</span>&gt;&lt;<a href="http://december.com/html/4/element/input.html"><span class="kw2">input</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;file&quot;</span> <span class="kw3">name</span><span class="sy0">=</span><span class="st0">&quot;image&quot;</span> <span class="kw3">size</span><span class="sy0">=</span><span class="st0">&quot;40&quot;</span> <span class="sy0">/</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/td.html"><span class="kw2">td</span></a>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/tr.html"><span class="kw2">tr</span></a>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/tr.html"><span class="kw2">tr</span></a>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/td.html"><span class="kw2">td</span></a> <span class="kw3">align</span><span class="sy0">=</span><span class="st0">&quot;left&quot;</span> <span class="kw3">colspan</span><span class="sy0">=</span><span class="st0">&quot;2&quot;</span>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/ol.html"><span class="kw2">ol</span></a> <span class="kw3">style</span><span class="sy0">=</span><span class="st0">&quot;margin:0;padding:3px 0px 3px 15px&quot;</span>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span>Max file size: 175 KB.<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span>Allowed extensions: jpg, jpeg, gif, png.<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span>Max Dimension: <span class="sc2">&lt;<a href="http://december.com/html/4/element/em.html"><span class="kw2">em</span></a>&gt;</span>800<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/em.html"><span class="kw2">em</span></a>&gt;</span>px.<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span>
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/ol.html"><span class="kw2">ol</span></a>&gt;</span>
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/tr.html"><span class="kw2">tr</span></a>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/tr.html"><span class="kw2">tr</span></a>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/td.html"><span class="kw2">td</span></a> <span class="kw3">align</span><span class="sy0">=</span><span class="st0">&quot;left&quot;</span> <span class="kw3">colspan</span><span class="sy0">=</span><span class="st0">&quot;2&quot;</span>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/input.html"><span class="kw2">input</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;submit&quot;</span> <span class="kw3">name</span><span class="sy0">=</span><span class="st0">&quot;submit&quot;</span> <span class="kw3">value</span><span class="sy0">=</span><span class="st0">&quot;Submit!&quot;</span> <span class="kw3">style</span><span class="sy0">=</span><span class="st0">&quot;font: 14pt verdana&quot;</span> <span class="sy0">/</span>&gt;</span>
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/td.html"><span class="kw2">td</span></a>&gt;</span>
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/tr.html"><span class="kw2">tr</span></a>&gt;</span>
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/table.html"><span class="kw2">table</span></a>&gt;</span>
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/form.html"><span class="kw2">form</span></a>&gt;</span></pre></div></div>
<p><strong>This will create a form that looks like this:</strong></p>
<p><a name="form"></a></p>
<form action="#form" enctype="multipart/form-data" method="post">
<table border="0" cellspacing="0" cellpadding="2" width="100%" align="center">
<tbody>
<tr>
<td width="100" align="left">Max Width:</td>
<td align="left">
<input style="width: 120px;" maxlength="4" name="image_max_width" type="text" /> px.</td>
</tr>
<tr>
<td align="left">Max Height:</td>
<td align="left">
<input style="width: 120px;" maxlength="4" name="image_max_height" type="text" /> px.</td>
</tr>
<tr>
<td align="left">Image:</td>
<td align="left">
<input name="image" size="40" type="file" /></td>
</tr>
<tr>
<td colspan="2" align="left">
<ol style="margin: 0; padding: 3px 0px 3px 15px;">
<li>Max file size: 175 KB</li>
<li>Allowed extensions: jpg, jpeg, gif, png.</li>
<li>Max Dimension: <em>800</em>px.</li>
</ol>
</td>
</tr>
<tr>
<td align="left colspa=">
<input style="font: 14pt verdana;" name="submit" type="submit" value="Submit!" /></td>
</tr>
</tbody>
</table>
</form>
<p>Then we just have to call the functions returned value (<em>$upload_and_resize</em>).</p>
<div id="wpshdo_8" class="wp-synhighlighter-outer"><div id="wpshdt_8" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_8"></a><a id="wpshat_8" class="wp-synhighlighter-title" href="#codesyntax_8"  onClick="javascript:wpsh_toggleBlock(8)" title="Click to show/hide code block">Show Upload and Resize</a></td><td align="right"><a href="#codesyntax_8" onClick="javascript:wpsh_code(8)" title="Show code only"><img border="0" style="border: 0 none" src="http://bgallz.org/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_8" onClick="javascript:wpsh_print(8)" title="Print code"><img border="0" style="border: 0 none" src="http://bgallz.org/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://bgallz.org/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://bgallz.org/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_8" class="wp-synhighlighter-inner" style="display: block;"><pre class="php" style="font-family:monospace;">&lt;div id=&quot;upload&quot;&gt;
<span class="kw2">&lt;?php</span> <span class="kw1">echo</span> <span class="re0">$upload_and_resize</span><span class="sy0">;</span> <span class="sy1">?&gt;</span>
&lt;/div&gt;</pre></div></div>
<input id="gwProxy" type="hidden" />
<p><!--Session data--></p>
<input id="jsProxy" onclick="jsCall();" type="hidden" />
<input id="gwProxy" type="hidden" />
<input id="jsProxy" onclick="jsCall();" type="hidden" />
<input id="gwProxy" type="hidden" />
<input id="jsProxy" onclick="jsCall();" type="hidden" />
<img src="http://bgallz.org/?ak_action=api_record_view&id=502&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://bgallz.org/502/php-upload-resize-image/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>PHP Favicon Generator Script</title>
		<link>http://bgallz.org/488/php-favicon-generator-script/</link>
		<comments>http://bgallz.org/488/php-favicon-generator-script/#comments</comments>
		<pubDate>Sat, 24 Jul 2010 18:12:40 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[favicon]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://bgallz.org/?p=488</guid>
		<description><![CDATA[I decided to make a free easy to use favicon generating script that uses PHP. The script has a few features and requirements when uploading your image to be converted to a favicon. First the script checks for a few things such as file type, file size, if the directory is writable, and the specified dimensions. You can create a ...]]></description>
			<content:encoded><![CDATA[<p>I decided to make a free easy to use favicon generating script that uses PHP. The script has a few features and requirements when uploading your image to be converted to a favicon. First the script checks for a few things such as file type, file size, if the directory is writable, and the specified dimensions. You can create a 16&#215;16 icon or a 32&#215;32 icon.</p>
<p><a title="Favicon Generator Script" href="http://bgallz.org/favicon-generator/" target="_blank"><strong>Click here to check out the demo for this script!</strong></a></p>
<p>Just select the image file you want converted to a 16&#215;16 or 32&#215;32 icon and hit submit! It&#8217;s that easy. Here is how it works:</p>
<div id="wpshdo_9" class="wp-synhighlighter-outer"><div id="wpshdt_9" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_9"></a><a id="wpshat_9" class="wp-synhighlighter-title" href="#codesyntax_9"  onClick="javascript:wpsh_toggleBlock(9)" title="Click to show/hide code block">Favicon Generator Script</a></td><td align="right"><a href="#codesyntax_9" onClick="javascript:wpsh_code(9)" title="Show code only"><img border="0" style="border: 0 none" src="http://bgallz.org/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_9" onClick="javascript:wpsh_print(9)" title="Print code"><img border="0" style="border: 0 none" src="http://bgallz.org/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://bgallz.org/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://bgallz.org/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_9" class="wp-synhighlighter-inner" style="display: block;"><pre class="php" style="font-family:monospace;"><span class="kw2">&lt;?php</span>
<span class="co1">// bgallz.org - Web coding and design tutorials, scripts, resources and more.</span>
<span class="co1">// favicon Generator Script</span>
<span class="kw2">function</span> generate_favicon<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
<span class="co1">// Create favicon.</span>
<span class="re0">$postvars</span> <span class="sy0">=</span> <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="st0">&quot;image&quot;</span> <span class="sy0">=&gt;</span> <a href="http://www.php.net/trim"><span class="kw3">trim</span></a><span class="br0">&#40;</span><span class="re0">$_FILES</span><span class="br0">&#91;</span><span class="st0">&quot;image&quot;</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st0">&quot;name&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">,</span>
<span class="st0">&quot;image_tmp&quot;</span>        <span class="sy0">=&gt;</span> <span class="re0">$_FILES</span><span class="br0">&#91;</span><span class="st0">&quot;image&quot;</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st0">&quot;tmp_name&quot;</span><span class="br0">&#93;</span><span class="sy0">,</span>
<span class="st0">&quot;image_size&quot;</span>    <span class="sy0">=&gt;</span> <span class="br0">&#40;</span>int<span class="br0">&#41;</span><span class="re0">$_FILES</span><span class="br0">&#91;</span><span class="st0">&quot;image&quot;</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st0">&quot;size&quot;</span><span class="br0">&#93;</span><span class="sy0">,</span>
<span class="st0">&quot;image_dimensions&quot;</span>    <span class="sy0">=&gt;</span> <span class="br0">&#40;</span>int<span class="br0">&#41;</span><span class="re0">$_POST</span><span class="br0">&#91;</span><span class="st0">&quot;image_dimensions&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="re0">$valid_exts</span> <span class="sy0">=</span> <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="st0">&quot;jpg&quot;</span><span class="sy0">,</span><span class="st0">&quot;jpeg&quot;</span><span class="sy0">,</span><span class="st0">&quot;gif&quot;</span><span class="sy0">,</span><span class="st0">&quot;png&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="re0">$ext</span> <span class="sy0">=</span> <a href="http://www.php.net/end"><span class="kw3">end</span></a><span class="br0">&#40;</span><a href="http://www.php.net/explode"><span class="kw3">explode</span></a><span class="br0">&#40;</span><span class="st0">&quot;.&quot;</span><span class="sy0">,</span><a href="http://www.php.net/strtolower"><span class="kw3">strtolower</span></a><span class="br0">&#40;</span><a href="http://www.php.net/trim"><span class="kw3">trim</span></a><span class="br0">&#40;</span><span class="re0">$_FILES</span><span class="br0">&#91;</span><span class="st0">&quot;image&quot;</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st0">&quot;name&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="re0">$directory</span> <span class="sy0">=</span> <span class="st0">&quot;favicon/&quot;</span><span class="sy0">;</span> <span class="co1">// Directory to save favicons. Include trailing slash.</span>
<span class="co1">// Check not larger than 175kb.</span>
<span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$postvars</span><span class="br0">&#91;</span><span class="st0">&quot;image_size&quot;</span><span class="br0">&#93;</span> <span class="sy0">&lt;=</span> <span class="nu0">179200</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
<span class="co1">// Check is valid extension.</span>
<span class="kw1">if</span><span class="br0">&#40;</span><a href="http://www.php.net/in_array"><span class="kw3">in_array</span></a><span class="br0">&#40;</span><span class="re0">$ext</span><span class="sy0">,</span><span class="re0">$valid_exts</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
<span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$ext</span> <span class="sy0">==</span> <span class="st0">&quot;jpg&quot;</span> <span class="sy0">||</span> <span class="re0">$ext</span> <span class="sy0">==</span> <span class="st0">&quot;jpeg&quot;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
<span class="re0">$image</span> <span class="sy0">=</span> <a href="http://www.php.net/imagecreatefromjpeg"><span class="kw3">imagecreatefromjpeg</span></a><span class="br0">&#40;</span><span class="re0">$postvars</span><span class="br0">&#91;</span><span class="st0">&quot;image_tmp&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="kw1">else</span> <span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$ext</span> <span class="sy0">==</span> <span class="st0">&quot;gif&quot;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
<span class="re0">$image</span> <span class="sy0">=</span> <a href="http://www.php.net/imagecreatefromgif"><span class="kw3">imagecreatefromgif</span></a><span class="br0">&#40;</span><span class="re0">$postvars</span><span class="br0">&#91;</span><span class="st0">&quot;image_tmp&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="kw1">else</span> <span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$ext</span> <span class="sy0">==</span> <span class="st0">&quot;png&quot;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
<span class="re0">$image</span> <span class="sy0">=</span> <a href="http://www.php.net/imagecreatefrompng"><span class="kw3">imagecreatefrompng</span></a><span class="br0">&#40;</span><span class="re0">$postvars</span><span class="br0">&#91;</span><span class="st0">&quot;image_tmp&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<a href="http://www.php.net/list"><span class="kw3">list</span></a><span class="br0">&#40;</span><span class="re0">$width</span><span class="sy0">,</span><span class="re0">$height</span><span class="br0">&#41;</span> <span class="sy0">=</span> <a href="http://www.php.net/getimagesize"><span class="kw3">getimagesize</span></a><span class="br0">&#40;</span><span class="re0">$postvars</span><span class="br0">&#91;</span><span class="st0">&quot;image_tmp&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="re0">$newwidth</span> <span class="sy0">=</span> <span class="re0">$postvars</span><span class="br0">&#91;</span><span class="st0">&quot;image_dimensions&quot;</span><span class="br0">&#93;</span><span class="sy0">;</span>
<span class="re0">$newheight</span> <span class="sy0">=</span> <span class="re0">$postvars</span><span class="br0">&#91;</span><span class="st0">&quot;image_dimensions&quot;</span><span class="br0">&#93;</span><span class="sy0">;</span>
<span class="re0">$tmp</span> <span class="sy0">=</span> <a href="http://www.php.net/imagecreatetruecolor"><span class="kw3">imagecreatetruecolor</span></a><span class="br0">&#40;</span><span class="re0">$newwidth</span><span class="sy0">,</span><span class="re0">$newheight</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="co1">// Copy the image to one with the new width and height.</span>
<a href="http://www.php.net/imagecopyresampled"><span class="kw3">imagecopyresampled</span></a><span class="br0">&#40;</span><span class="re0">$tmp</span><span class="sy0">,</span><span class="re0">$image</span><span class="sy0">,</span>0<span class="sy0">,</span>0<span class="sy0">,</span>0<span class="sy0">,</span>0<span class="sy0">,</span><span class="re0">$newwidth</span><span class="sy0">,</span><span class="re0">$newheight</span><span class="sy0">,</span><span class="re0">$width</span><span class="sy0">,</span><span class="re0">$height</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="re0">$rand</span> <span class="sy0">=</span> <a href="http://www.php.net/rand"><span class="kw3">rand</span></a><span class="br0">&#40;</span>1000<span class="sy0">,</span>9999<span class="br0">&#41;</span><span class="sy0">;</span>
<span class="re0">$filename</span> <span class="sy0">=</span> <span class="st0">&quot;./&quot;</span><span class="sy0">.</span><span class="re0">$directory</span><span class="sy0">.</span><span class="re0">$rand</span><span class="sy0">.</span><span class="re0">$postvars</span><span class="br0">&#91;</span><span class="st0">&quot;image&quot;</span><span class="br0">&#93;</span><span class="sy0">;</span>
<span class="co1">// Create image file with 100% quality.</span>
<span class="kw1">if</span><span class="br0">&#40;</span><a href="http://www.php.net/is_writable"><span class="kw3">is_writable</span></a><span class="br0">&#40;</span><span class="re0">$directory</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
<a href="http://www.php.net/imagejpeg"><span class="kw3">imagejpeg</span></a><span class="br0">&#40;</span><span class="re0">$tmp</span><span class="sy0">,</span><span class="re0">$filename</span><span class="sy0">,</span>100<span class="br0">&#41;</span><span class="sy0">;</span>
<span class="co1">// Image created, now rename it to its</span>
<span class="re0">$ext_pos</span> <span class="sy0">=</span> <a href="http://www.php.net/strpos"><span class="kw3">strpos</span></a><span class="br0">&#40;</span><span class="re0">$postvars</span><span class="br0">&#91;</span><span class="st0">&quot;image&quot;</span><span class="br0">&#93;</span><span class="sy0">,</span><span class="st0">&quot;.&quot;</span> <span class="sy0">.</span> <span class="re0">$ext</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="re0">$strip_ext</span> <span class="sy0">=</span> <a href="http://www.php.net/substr"><span class="kw3">substr</span></a><span class="br0">&#40;</span><span class="re0">$postvars</span><span class="br0">&#91;</span><span class="st0">&quot;image&quot;</span><span class="br0">&#93;</span><span class="sy0">,</span>0<span class="sy0">,</span><span class="re0">$ext_pos</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="co1">// Rename image to .ico file</span>
<a href="http://www.php.net/rename"><span class="kw3">rename</span></a><span class="br0">&#40;</span><span class="re0">$filename</span><span class="sy0">,</span><span class="st0">&quot;./favicon/&quot;</span><span class="sy0">.</span><span class="re0">$strip_ext</span><span class="sy0">.</span><span class="st0">&quot;.ico&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="kw1">return</span> <span class="st0">&quot;&lt;strong&gt;Icon Preview:&lt;/stong&gt;
&lt;p&gt;&lt;img title=&quot;</span>\Favicon Preview\<span class="st0">&quot; src=&quot;</span>\<span class="st0">&quot;.<span class="es4">$filename</span>.&quot;</span>\<span class="st0">&quot; border=&quot;</span>\<span class="nu0">0</span>\<span class="st0">&quot; alt=<span class="es1">\&quot;</span>Favicon<span class="es1">\&quot;</span> /&gt;&lt;/p&gt;
&lt;p&gt;Favicon successfully generated. &lt;a name=&quot;</span>\Download Favicon\<span class="st0">&quot; href=<span class="es1">\&quot;</span>&quot;</span><span class="sy0">.</span><span class="re0">$filename</span><span class="sy0">.</span><span class="st0">&quot;<span class="es1">\&quot;</span> target=<span class="es1">\&quot;</span>_blank<span class="es1">\&quot;</span>&gt;Click here to download your favicon.&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;If favicon doesn't download, right click the link above. Click SAVE AS to download .ico.&lt;/strong&gt;&quot;</span><span class="sy0">;</span>
<span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span>
<span class="kw1">return</span> <span class="st0">&quot;The directory: <span class="es1">\&quot;</span>&quot;</span><span class="sy0">.</span><span class="re0">$directory</span><span class="sy0">.</span><span class="st0">&quot;<span class="es1">\&quot;</span> is not writable.&quot;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<a href="http://www.php.net/imagedestroy"><span class="kw3">imagedestroy</span></a><span class="br0">&#40;</span><span class="re0">$image</span><span class="br0">&#41;</span><span class="sy0">;</span>
<a href="http://www.php.net/imagedestroy"><span class="kw3">imagedestroy</span></a><span class="br0">&#40;</span><span class="re0">$tmp</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span>
<span class="kw1">return</span> <span class="st0">&quot;File size too large. Max allowed file size is 175kb.&quot;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span>
<span class="kw1">return</span> <span class="st0">&quot;Invalid file type. You must upload an image file. (jpg, jpeg, gif, png).&quot;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="br0">&#125;</span>
<span class="kw1">if</span><span class="br0">&#40;</span><a href="http://www.php.net/isset"><span class="kw3">isset</span></a><span class="br0">&#40;</span><span class="re0">$_GET</span><span class="br0">&#91;</span><span class="st0">&quot;do&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
<span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$_GET</span><span class="br0">&#91;</span><span class="st0">&quot;do&quot;</span><span class="br0">&#93;</span> <span class="sy0">==</span> <span class="st0">&quot;create&quot;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
<span class="kw1">if</span><span class="br0">&#40;</span><a href="http://www.php.net/isset"><span class="kw3">isset</span></a><span class="br0">&#40;</span><span class="re0">$_POST</span><span class="br0">&#91;</span><span class="st0">&quot;submit&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
<span class="re0">$generate_favicon</span> <span class="sy0">=</span> <span class="st0">&quot;&quot;</span><span class="sy0">.</span>generate_favicon<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">.</span><span class="st0">&quot;&quot;</span><span class="sy0">;</span>
<span class="re0">$generate_favicon</span> <span class="sy0">.=</span> <span class="st0">&quot;Place your download instructions and anything else you want here to follow the download link after upload.&quot;</span><span class="sy0">;</span>
<span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span>
<span class="re0">$generate_favicon</span> <span class="sy0">=</span> <span class="st0">&quot;&quot;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="br0">&#125;</span>
<span class="br0">&#125;</span>
<span class="sy1">?&gt;</span></pre></div></div>
<p>Then we must include the HTML form that will submit the image and dimensions to PHP:</p>
<div id="wpshdo_10" class="wp-synhighlighter-outer"><div id="wpshdt_10" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_10"></a><a id="wpshat_10" class="wp-synhighlighter-title" href="#codesyntax_10"  onClick="javascript:wpsh_toggleBlock(10)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_10" onClick="javascript:wpsh_code(10)" title="Show code only"><img border="0" style="border: 0 none" src="http://bgallz.org/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_10" onClick="javascript:wpsh_print(10)" title="Print code"><img border="0" style="border: 0 none" src="http://bgallz.org/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://bgallz.org/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://bgallz.org/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_10" class="wp-synhighlighter-inner" style="display: block;"><pre class="html4strict" style="font-family:monospace;"><span class="sc2">&lt;<a href="http://december.com/html/4/element/form.html"><span class="kw2">form</span></a> <span class="kw3">action</span><span class="sy0">=</span><span class="st0">&quot;index.php?do=create&quot;</span>  <span class="kw3">enctype</span><span class="sy0">=</span><span class="st0">&quot;multipart/form-data&quot;</span> <span class="kw3">method</span><span class="sy0">=</span><span class="st0">&quot;post&quot;</span>&gt;</span>Image Dimensions:<span class="sc2">&lt;<a href="http://december.com/html/4/element/br.html"><span class="kw2">br</span></a> <span class="sy0">/</span>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/select.html"><span class="kw2">select</span></a> <span class="kw3">style</span><span class="sy0">=</span><span class="st0">&quot;width: 170px;&quot;</span> <span class="kw3">name</span><span class="sy0">=</span><span class="st0">&quot;image_dimensions&quot;</span>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/option.html"><span class="kw2">option</span></a> <span class="kw3">selected</span><span class="sy0">=</span><span class="st0">&quot;selected&quot;</span> <span class="kw3">value</span><span class="sy0">=</span><span class="st0">&quot;16&quot;</span>&gt;</span>16px x 16px<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/option.html"><span class="kw2">option</span></a>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/option.html"><span class="kw2">option</span></a> <span class="kw3">value</span><span class="sy0">=</span><span class="st0">&quot;32&quot;</span>&gt;</span>32px x 32px<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/option.html"><span class="kw2">option</span></a>&gt;</span>
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/select.html"><span class="kw2">select</span></a>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/p.html"><span class="kw2">p</span></a>&gt;&lt;<a href="http://december.com/html/4/element/span.html"><span class="kw2">span</span></a> <span class="kw3">style</span><span class="sy0">=</span><span class="st0">&quot;font-size: 14pt;&quot;</span>&gt;</span>Favicon Image:<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/span.html"><span class="kw2">span</span></a>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/p.html"><span class="kw2">p</span></a>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/input.html"><span class="kw2">input</span></a> <span class="kw3">name</span><span class="sy0">=</span><span class="st0">&quot;image&quot;</span> <span class="kw3">size</span><span class="sy0">=</span><span class="st0">&quot;40&quot;</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;file&quot;</span> <span class="sy0">/</span>&gt;</span>
<span class="sc2">&lt;<a href="http://december.com/html/4/element/input.html"><span class="kw2">input</span></a> <span class="kw3">style</span><span class="sy0">=</span><span class="st0">&quot;font: 14pt verdana;&quot;</span> <span class="kw3">name</span><span class="sy0">=</span><span class="st0">&quot;submit&quot;</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;submit&quot;</span> <span class="kw3">value</span><span class="sy0">=</span><span class="st0">&quot;Submit!&quot;</span> <span class="sy0">/</span>&gt;</span></pre></div></div>
<p>Be sure to include the HTML head tags in your HTML pages that use the favicon. These are given on the script&#8217;s index and on the demo.</p>
<p><a href="http://bgallz.org/bgallz.org-favicon-generator.rar" target="_blank"><strong>Click here to download the script!</strong></a></p>
<img src="http://bgallz.org/?ak_action=api_record_view&id=488&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://bgallz.org/488/php-favicon-generator-script/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>PHP Ordinalize Numbers – Add Suffix</title>
		<link>http://bgallz.org/481/php-ordinalize-numbers-add-suffix/</link>
		<comments>http://bgallz.org/481/php-ordinalize-numbers-add-suffix/#comments</comments>
		<pubDate>Thu, 22 Jul 2010 22:23:29 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP Functions]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[numbers]]></category>
		<category><![CDATA[ordinalize]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://bgallz.org/?p=481</guid>
		<description><![CDATA[Here is a very simple function to use to ordinalize numbers in PHP. This adds the place value suffix to numbers. So you can turn numbers like 1, 2, 3 into 1st, 2nd, 3rd.
Here is the code:

function ordinalize($int){
if(in_array(($int % 100),range(11,13))){
return $int . "th";
} else {
switch(($int % 10)){
case 1:
return $int . "st";
break;
case 2:
return $int . "nd";
break;
case 3:
return $int . "rd";
break;
default:
return $int ...]]></description>
			<content:encoded><![CDATA[<p>Here is a very simple function to use to ordinalize numbers in PHP. This adds the place value suffix to numbers. So you can turn numbers like 1, 2, 3 into 1st, 2nd, 3rd.</p>
<p>Here is the code:</p>
<pre>
function ordinalize($int){
if(in_array(($int % 100),range(11,13))){
return $int . "th";
} else {
switch(($int % 10)){
case 1:
return $int . "st";
break;
case 2:
return $int . "nd";
break;
case 3:
return $int . "rd";
break;
default:
return $int . "th";
break;
}
}
}
</pre>
<p>Basically the function first checks if the number is in the range of 11-13, and if so it returns the number with &#8220;th&#8221; attached (11th, 12th, 13th). If it is not in this range it checks the remainder of the number divided by 10.</p>
<p>So let&#8217;s say our number was 34. 10 goes into 34 three times, with a remainder of 4. Now the function runs this value against three cases, those being 1, 2, and 3. Since it is not one of them, the default value is used, which is &#8220;th.&#8221; Thus returning &#8220;4th.&#8221;</p>
<p><strong>Example input:</strong></p>
<pre>
3
10
999
</pre>
<p><strong>Example output:</strong></p>
<pre>
3rd
10th
999th
</pre>
<p>Enjoy!</p>
<img src="http://bgallz.org/?ak_action=api_record_view&id=481&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://bgallz.org/481/php-ordinalize-numbers-add-suffix/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

