Generating a dynamic showcase using PHP

Introduction

This tutorial illustrates how to create image collections dynamically using server side script.
Instead of using several different showcase configuration files, one single, dynamic showcase configuration can be used to to display specific image collections.

In this tutorial we will demonstrate how this can be achieved using the popular scripting language PHP.
Using the sample code from this tutorial requires:

  • basic PHP knowledge
  • a webserver runnig PHP
  • a running image server

 

The Dynamic FSI Showcase Configuration File

Basically this is a standard FSI Showcase configuration file. The difference here is, that we enumerate the images to display using PHP script. In other words: we output the <image> nodes within the collection node <images> dynamically.

The first thing to point out here, is that this is not an .fsi file, but a .php file instead. The reason is, that web servers usually do not parse *.xml files by default.
As FSI configuration files are XML files, we will use PHP to generate the XML needed.
For each image the script adds an <Image></Image> node to the configuration.
Within the node you need to specify at least the ImagePath parameter (the path and file name of the source image) and can optionally define more parameters like the label to display.

Now, if we configure Showcase to use this configuration file, we can dynamically change the pictures being displayed in the showcase.

Lets take a look at the display.html file embedding the FSI Showcase instance.

The HTML File embedding FSI Viewer

In the HTML file embedding FSI Viewer we now need to use the dynamic configuration file described above and we need to append the paths to the images for the collection using a HTTP query appended to the dynamic configuration file “dynsc_template.php”.
Note that the configuration file (parameter “cfg”) in the object and embed tag for FSI Viewer is being provided as an absolute URL rather than a file name only.

Example:
http://www.domain.com/dynsc_template.php?images=[image1] | [image2] |…[imageN]

As FSI parameters provided by HTTP query may not contain “=” and “?`” characters, we need to encode the “cfg” parameter value using the PHP function rawurlencode:

[…]fsi.swf[…]&cfg=<?php echo rawurlencode(‘http://www.domain.com/dynsc_template.php?images=[image1] | [image2] |…[imageN]‘); ?>

The [image]s specified must contain the path to the source image on your imaging server, e.g. images/Flowers/mypic.tif.
We seperate each image path using a “|” character.

 

In display.html we set the configuration file to be used for Showcase to a full valid URL,
http://www.domain.com/dynsc_template.php
and pass the $_REQUEST[‘images’] to the dsync_template.php which generates a valid XML-Image tag for each image specified.

Crossdomain Considerations

Please note that Adobe Flash Player can – by default – not retrieve XML data from a foreign domain. This is: an FSI Viewer instance located at http://somedomain/fsi.swf is not allowed to read XML data from http://anotherdomain/data.xml. In addition to that, Adobe Flash Player does not resolve domains to IP addresses. So do not mix adressing via IP addresses and domains.

To work around, that you need to request XML data from an other domain than you are loading FSI Viewer from, add a crossdomain policy file to the root directory of the domain your server side script resides in, e.g. http://anotherdomain/crossdomain.xml