The SQPhoto App: Rendering Photos Dynamically with Flex and PHP

by Pete Mackie

The advent of digital cameras has generated a plethora of photos, so we need new and convenient ways to publish these photos online. Furthermore, we need a repository that stores and indexes these thousands of photos, then subsequently renders them for viewing in a Flex-based rich Internet application (RIA).

This article discusses SQPhoto, a PHP and Flex-based photo-rendering RIA that pulls the photos from a MySQL database with Action Message Format (AMF3) messaging through the WebORB for PHP application server. This RIA has a number of advantages.

First, the SQPhoto Flex client caches the photos it receives via remoting as an array before rendering. This eliminates photo flickering when we update the display.

Second, the photo arrays received from a PHP server present a problem, as PHP and Flex disagree as to their data type. PHP insists that photos have string format and allows no other data type, even if force-cast. Flex prefers, and also insists on, receiving photos as ActionScript3 (AS3) ByteArrays. Simply put, PHP photo string and Flex photo ByteArray objects are not compatible in any way. I have yet to see a PHP application server that can properly return photos to the Flex client via AMF3 messaging. In the SQPhoto application, I have developed WebORB application server update code that dynamically converts PHP photo strings to AMF ByteArray data streams for transfer to the Flex client.

Third, some Flex developers have difficulty returning arrays of PHP objects (photos and metadata, in this example) from the server to the Flex client and then rendering the received objects. In this article, I will share some of the PHP-to-Flex RemoteObject array transfer techniques that I have successfully used.

Finally, I will provide the methods to search for and retrieve photos from the MySQL SQPhoto database repository using metadata — specifically, keyword and photo caption data fields in the photo database table.

Read more of this article in Flex Authority Volume 2 Issue 1!

Purchase the Issue or Subscribe to Flex Authority!

 

Companion Articles

Interested in learning more about the SQPhoto application and dealing with photos in Flex and PHP? Read Pete Mackie's companion articles, available online:

The SQPhoto App: Transferring Photos from the PHP Server to the Flex Client

The SQPhoto App: Caching Your Photos with Flex and PHP

ColdFusion 8 VPS hosting plans