The making of ChessJam Flex/AIR + ColdFusion + LiveCycle DS = fun project!

A few weeks ago, I unveiled a weekend project that I’ve been involved in for several months called ChessJam.  I am now making good on my promise to share why we the selected the technologies behind this desktop application for playing online head-to-head chess. Obviously this is primarily a personal project but there is a [...]

ColdFusion versus PHP – Uploading a File

I spent part of my vacation digging into PHP. I’d like to be much savvier with PHP because we’ve seen a big chunk of Flex adoption from the PHP community and I’d like to be able to talk to those developers more intelligently. Unfortunately my server-side programming chops are very, very rusty. I started out as a ColdFusion developer and I’ve been able to play with some of the new stuff in ColdFusion 9 but I haven’t built a real CF app in a long time. So I thought I’d do a bit of a comparison and I’ve started doing simple things in PHP and then replicating them in ColdFusion. The first one is file uploading.

Disclaimer: I’m assuming there are things I’m doing wrong. File uploading is fairly basic, but part of the reason I want to blog the basic stuff is so people can let me know where I’m messing up and what I could do better. So flame on in the comments.

The Code Comparison

PHP – file_upload.php

<body>
<?php
ini_set('display_errors',1);
error_reporting(E_ALL | E_STRICT);
 
if(isset($_POST['submitted']))
{
if( move_uploaded_file($_FILES['myfile']['tmp_name'], "{$_FILES['myfile']['name']}") )
{
print '<p>It verked!</p>';
} else {
print '<p>Problemo!</p>';
}
print_r($_FILES);
}
?>
<form action="upload_file.php" enctype="multipart/form-data" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="3000000" />
<p><input type="file" name="myfile" /></p>
<p><input type="submit" name="submit" value="Upload" /></p>
<input type="hidden" name="submitted" value="true" />
</form>
</body>

ColdFusion – file_upload.cfm

<cfifisDefined("form.submitted">
<cfset currentPath = getCurrentTemplatePath()>
<cfset currentDirectory = getDirectoryFromPath(currentPath)>
<cffile action="upload" nameconflict="overwrite" filefield="form.myfile" destination="#currentDirectory#/coldfusion.gpx"/>
<cfif cffile.filewassaved eq true>
<p>It verked!</p>
<cfdump var="#cffile#"/>
<cfelse>
<p>Problemo!</p>
</cfif>
</cfif>
<body>
<formaction="upload_file.cfm" enctype="multipart/form-data" method="POST">
<p><inputtype="file" name="myfile" /></p>
<p><inputtype="submit" name="submit" value="Upload" /></p>
<inputtype="hidden" name="submitted" value="true" />
</form>
</body>

Thoughts

I thought it was interesting how PHP and ColdFusion differ in the actual upload mechanism. Both of them just upload the file to a temporary location but then how the programmer deals with it is different. With PHP, you “move” the file to a location of your choice with the move_uploaded_file method. With ColdFusion you use cffile but call the upload attribute instead of the move attribute. That's why you don't put # signs around the form.myfile attribute because the upload function in cffile uses the POST info and that filefield attribute to to the moving/copying behind the scenes. Not sure which one I like better.

A few other bits. One, ColdFusion seems to give way, way more information about the file you've uploaded. I don't know if there is a way to get that kind of detail from PHP, but with ColdFusion I get a bunch of attributes like filewassaved, fileexisted, filewasappended, serverfileext, serverfilename etc. Some of that I can parse from the PHP information, like the file name and file extension, but others, like if it was overwritten, or if the file already existed, don't seem possible to get with PHP. Two, it is really, really annoying to use a relative file path with ColdFusion. The move_uploaded_file function uses a relative path so it's easy to upload it to the same directory. With ColdFusion, it's a pain which is why I had to set a couple of extra variables. Also, PHP seems to love to check that you're below the max file size. You have to set one in your php.ini file and then send it again as a hidden form field. That seems completely redundant and I can't figure out why they do that.

Like I said above, this is supposed to be a pretty basic example because I want to know if I'm doing something stupid. If so, or if you have any additional info on my thoughts above, let me know.

New ChessJam blog created for game-specific posts

I’ve created a separate blog for ChessJam-specific news.  I will continue to blog about ChessJam here on Greg’s Ramblings but only when it’s relevant to the Adobe developer community.  For example, I’m working on a new post that goes into some details on how the app was built with Flex, AIR, ColdFusion and LiveCycle Data [...]

Why ColdFusion is worth its money

I’m currently installing this new dedicated RackSpaceCloud server. While I have fallen in love ColdFusion in the last year or so, I am still a CF n00b and not ready to completely switch. So my new server needs both ColdFusion (for new projects) and PHP (mainly for my WordPress blog).
After I installed Apache, MySql and PHP, [...]

ChessJam and Robots – A.I. saves the day

A few days ago, I blogged about the roll-out of ChessJam, an online chess app built on Flex/AIR, ColdFusion and LiveCycle Data Services.  The roll-out has gone well but we have quickly learned that our real challenge is creating a new chess playing community!   From analyzing our logs, here is the typical experience over the [...]

My pet project – ChessJam – live online chess with a fun attitude

For the past eight months, I’ve been working with two friends, Todd Williams and Sean Carey, on a little side project called ChessJam.  This project started in February, 2009 when Sean and I decided to play a game of online chess with each other to finally resolve who was the better player.  We explored several [...]

Behind the scenes of the MAX widget – ColdFusion, FMS and Flex

While I was taking some time off, I thought it would be a good idea to give you a peak at what’s running behind the scenes of the MAX widget and why I chose ColdFusion and Flex to build it.
Why ColdFusion?
There are a number of reasons why I chose ColdFusion but the main reason is [...]

CFUnited Thoughts

cfunited_logoI had a great week at CFUnited last week and it’s great to see the ColdFusion community continue to set the bar for enthusiasm and camaraderie. Brian Swartzfager, Jeff Coughlin, and Dan Vega have great writeups. Adam Haskell has a rundown of some of the presentations and you can grab some of the slides over at SlideSix.

I was impressed both with the response to our news about ColdFusion 9, the new features, and the Flex track that Andy Powell helped with. Having guys like Doug McCune present alongside ColdFusion rockstars like Ray Camden is great for both communities. ColdFusion has a few new features that are going to lower the barrier for non-CF RIA developers to start using ColdFusion. ColdFusion as a Service makes it easy to use ColdFusion to accomplish things right inside your Flex application like send an email or generate a document that you can’t do with just Flex. The ColdFusion-AIR functionality makes online/offline sync (something that’s tough to do) a breeze. We’ve always talked about the fact that ColdFusion is the best middle and back end for creating RIAs and as the sophistication of Flex/AIR have evolved, ColdFusion has kept pace.

And there’s nothing like the ColdFusion community. It’s a welcoming, but still tight-knit community that’s willing to help anyone regardless of skill level. It was great to see people I’ve met on the road and meet a few new people as well. Congrats to the team at Stellr for putting on a great show. I really encourage any Flex (and ColdFusion) developer to check it out. And then come check out 360|Flex. Between these two conferences we’ve got a lot of knowledge out there.

ColdFusion 9 & Flex 4 Application Development: Slides for my CFUnited Talk Tomorrow

I’m a lazy slacker so my talk at CFUnited, ColdFusion 9 & Flex 4: Application Development doesn’t have any session description. I’m assuming that means I’ll probably have 2 people there, especially because it looks like CFUnited has an awesome speaker lineup (yet again) but for anyone who wants them or wants to see what I’ll be talking about I’ve posted my slides below and uploaded them to Share. I’ll be covering the new data wizards in Flash Builder 4, some new features in the Flex 4 SDK, and topping it off with how to use the ColdFusion as a Service feature in your Flex applications.