<?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>Andrew's Tech Musings &#187; Tips</title>
	<atom:link href="http://andrewcurioso.com/tag/tips/feed/" rel="self" type="application/rss+xml" />
	<link>http://andrewcurioso.com</link>
	<description>Tech, Social Media, PHP, Opinions</description>
	<lastBuildDate>Sat, 04 Sep 2010 12:37:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Detecting file size overflow in PHP</title>
		<link>http://andrewcurioso.com/2010/06/detecting-file-size-overflow-in-php/</link>
		<comments>http://andrewcurioso.com/2010/06/detecting-file-size-overflow-in-php/#comments</comments>
		<pubDate>Thu, 10 Jun 2010 03:55:06 +0000</pubDate>
		<dc:creator>Andrew Curioso</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://andrewcurioso.com/?p=232</guid>
		<description><![CDATA[One of the things that separates a good web application from a great one is how gracefully they handle failures. One of the often overlooked cases is when a user attempts to upload a file that exceeds the set PHP upload file size. This article shows how to detect when the user tries to upload [...]]]></description>
			<content:encoded><![CDATA[<p>One of the things that separates a good web application from a great one is how gracefully they handle failures. One of the often overlooked cases is when a user attempts to upload a file that exceeds the set PHP upload file size. This article shows how to detect when the user tries to upload a file that is too large and display an appropriate message.<br />
<span id="more-232"></span><br />
This article assumes that you have already set upload_max_filesize, post_max_size, and memory_limit in your php.ini file to appropriate values. It also assumes that you already have a working file upload form. There are plenty of tutorials out there already to get you started. </p>
<p>If you can, you may want to set post_max_size to a low value (say &#8220;1M&#8221;) to make testing easier. </p>
<p>First test to see how your script behaves. Try uploading a file that is larger than post_max_size. If you do you will get a message like this in your error log:</p>
<pre class="brush: plain;">
[09-Jun-2010 19:28:01] PHP Warning:  POST Content-Length of 30980857 bytes exceeds the limit of 2097152 bytes in Unknown on line 0
</pre>
<p>If you&#8217;re not careful this can lead to unexpected behavior in your application. The end result can range from silent failure all the way to lost customers.</p>
<h2>Solving the problem</h2>
<p>The PHP documentation provides a hack to solve this problem:</p>
<blockquote><p>If the size of post data is greater than post_max_size, the $_POST and $_FILES  superglobals  are empty. This can be tracked in various ways, e.g. by passing the $_GET variable to the script processing the data, i.e. &lt;form action=&#8221;edit.php?processed=1&#8243;&gt;, and then checking if $_GET['processed'] is set.<br />
<a href="http://php.net/manual/en/ini.core.php" class="citation">Source: PHP manual</a></p></blockquote>
<p>To be clear, it is suggesting that you pass a value in the query string along with your form. If the value is in the $_GET superglobal and both $_FILE and $_POST are empty then the maximum upload size is exceeded. There are two problems with this approach: it adds extra complexity on the front-end and it can potential give a false positive.</p>
<p>Extra complexity on the front-end means extra documentation and more room for mistakes. And if there is a mistake it may not be caught for a long time (does your QA team routinely upload large files?).  In this case we already have all the data that we need to determine if the maximum file size was exceeded without adding extra complexity and headache for developers.</p>
<p>We know what type of request is being processed, we have the $_POST and $_FILES arrays, and we have the content length as it was passed to the HTTP server from the client.  From that we get this code:</p>
<pre class="brush: php;">
if ( $_SERVER['REQUEST_METHOD'] == 'POST' &amp;&amp; empty($_POST) &amp;&amp;
     empty($_FILES) &amp;&amp; $_SERVER['CONTENT_LENGTH'] &gt; 0 )
{
  $displayMaxSize = ini_get('post_max_size');

  switch ( substr($displayMaxSize,-1) )
  {
    case 'G':
      $displayMaxSize = $displayMaxSize * 1024;
    case 'M':
      $displayMaxSize = $displayMaxSize * 1024;
    case 'K':
       $displayMaxSize = $displayMaxSize * 1024;
  }

  $error = 'Posted data is too large. '.
           $_SERVER[CONTENT_LENGTH].
           ' bytes exceeds the maximum size of '.
           $displayMaxSize.' bytes.&quot;;
}
</pre>
<p>The important thing to notice is the &#8220;if&#8221; statement on lines one and two. The example code just sets an error string. Production code might display a message to the user, execute some Javascript (for asynchronous uploads), or pass back a XML or Json object for Flash clients.</p>
<p>I&#8217;ve tested this code with Apache as both a module and as CGI. As far as I know it should work fine with IIS as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewcurioso.com/2010/06/detecting-file-size-overflow-in-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A method called &#8216;delete&#8217; in Flex and AS3</title>
		<link>http://andrewcurioso.com/2009/07/a-method-called-delete-in-flex-and-as3/</link>
		<comments>http://andrewcurioso.com/2009/07/a-method-called-delete-in-flex-and-as3/#comments</comments>
		<pubDate>Thu, 02 Jul 2009 05:26:30 +0000</pubDate>
		<dc:creator>Andrew Curioso</dc:creator>
				<category><![CDATA[Flex and AS3]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://andrewcurioso.com/?p=137</guid>
		<description><![CDATA[You are in for a headache if you have try to call a method or create a member variable with the name of a reserved word in Actionscript. It can lead to such fun situations as having variables called: insert; update; deleteSomething. Because calling the third variable &#8220;delete&#8221; may be logical but it is a [...]]]></description>
			<content:encoded><![CDATA[<p>You are in for a headache if you have try to call a method or create a member variable with the name of a reserved word in Actionscript. It can lead to such fun situations as having variables called: insert; update; deleteSomething. Because calling the third variable &#8220;delete&#8221; may be logical but it is a reserved word so that is out of the question. It gets hairier when you don&#8217;t necessarily have control over the object format (such is often the case with remote calls). I ran into this today when trying to call the &#8220;node_delete&#8221; (or &#8220;node.delete&#8221;) method in Drupal via Services and AMFPHP. This is frustrating so I&#8217;m going to show two situations where you could run into this problem and how I fixed them.<br />
<span id="more-137"></span></p>
<h3>Situation #1: A variable named &#8220;new&#8221; in a dynamic class</h3>
<p>You are creating a dynamic object and you need to use a reserved word as a member variable name but you can&#8217;t.<br />
<span class="syntaxhighlighterContainer">
<pre class="brush: jscript;">
var x:Object = new Object;
x.new = &quot;this doesn't work&quot;;
x['new'] = &quot;this works&quot;;
</pre>
<p></span><br />
The first method is a nice way to get <em>1084: Syntax error: expecting identifier before new</em> when you try to compile. Remove that line and use just the second one and you are all set. It is OK to mix and match access methods, as long as you never use dot notation for reserved words.</p>
<h3>Situation #2: A RPC method named delete</h3>
<p>You are making a remote call via the RemoteObject class (such as I was doing with Drupal) and you need to call a method named &#8220;delete&#8221; (or &#8220;new&#8221; for that matter). You naturally try this:<br />
<span class="syntaxhighlighterContainer">
<pre class="brush: jscript;">
var ro:RemoteObject = new RemoteObject;
ro.endpoint = &quot;http://www.example.com/amfphp&quot;;
ro.delete( 1234 );
</pre>
<p></span><br />
You will be promptly greeted by the now familiar 1084 error when you try to compile and using a different notation won&#8217;t work. I&#8217;ll break the solution into multiple parts although it could just as easily be chained together:<br />
<span class="syntaxhighlighterContainer">
<pre class="brush: jscript;">
var op:AbstractOperation = ro.getOperation('delete');
op.send( 12345 );
</pre>
<p></span><br />
Incidentally the result of the &#8220;send&#8221; method is a AsyncToken object (the same object that &#8220;ro.delete()&#8221; would return if delete were not reserved) which can then be used to add responders.</p>
<p>There you have it. Two quick and easy ways to get around methods and properties with reserved words for names.</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewcurioso.com/2009/07/a-method-called-delete-in-flex-and-as3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Drop shadow tricks in Flex</title>
		<link>http://andrewcurioso.com/2009/06/drop-shadow-tricks-in-flex/</link>
		<comments>http://andrewcurioso.com/2009/06/drop-shadow-tricks-in-flex/#comments</comments>
		<pubDate>Tue, 16 Jun 2009 15:20:11 +0000</pubDate>
		<dc:creator>Andrew Curioso</dc:creator>
				<category><![CDATA[Flex and AS3]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://andrewcurioso.com/?p=53</guid>
		<description><![CDATA[Every display markup language has its frustrating moments. Adobe Flex isn&#8217;t any exception. I ran into a little trouble a while back when trying to put a drop shadow on a HBox component. Here is the effect that I wanted to achieve: It seems easy enough so let&#8217;s give this a try: &#60;mx:Style&#62; HBox { [...]]]></description>
			<content:encoded><![CDATA[<p>Every display markup language has its frustrating moments. Adobe Flex isn&#8217;t any exception. I ran into a little trouble a while back when trying to put a drop shadow on a HBox component. Here is the effect that I wanted to achieve:</p>
<div id="attachment_57" class="wp-caption alignnone" style="width: 321px"><img class="size-full wp-image-57" title="Flex form with drop shadow header" src="http://andrewcurioso.com/wp-content/uploads/2009/05/picture-6.png" alt="Flex form with drop shadow header" width="311" height="216" /><p class="wp-caption-text">Flex form with drop shadow header</p></div>
<p><span id="more-53"></span></p>
<p>It seems easy enough so let&#8217;s give this a try:<br />
<span class="syntaxhighlighterContainer">
<pre class="brush: xml;">
&lt;mx:Style&gt;
HBox {
  paddingTop: 5;
  paddingBottom: 5;
  paddingLeft: 5;
  paddingRight: 5;
  dropShadowEnabled: true;
}
&lt;/mx:Style&gt;
</pre>
<p></span></p>
<p>Usually the <em>dropShadowEnabled: true</em> would be enough but in this case you may be surprised if you put the above style into an MXML file with an HBox in it. Drop shadows don&#8217;t work on HBox components without some more tweaking. They don&#8217;t work for VBox, FormItem, Canvas, Grid, and Tile either. But dropShadowEnabled works beautifully to create Flex drop shadows on a component like TextInput.</p>
<p>What sets TextInput apart? It has a border by default. That is the key. Put <em>borderStyle: solid</em> in our style sheet then all the sudden our HBox has a drop shadow. Unfortunately it also has a nice one pixel border as well. To fix that we can set the borderThickness to zero and you&#8217;re done.</p>
<p><span class="syntaxhighlighterContainer">
<pre class="brush: xml;">
&lt;mx:Style&gt;
HBox {
  paddingTop: 5;
  paddingBottom: 5;
  paddingLeft: 5;
  paddingRight: 5;
  dropShadowEnabled: true;
  borderThickness: 0;
  borderStyle: solid;
}
&lt;/mx:Style&gt;
</pre>
<p></span></p>
<h3>Quick Two Point Summary</h3>
<ul>
<li>Drop shadows will be hidden if the component doesn&#8217;t have a border.</li>
<li>The border can be zero pixels.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://andrewcurioso.com/2009/06/drop-shadow-tricks-in-flex/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
