You are here

Loading images into Shockwave from PHP or a database

Director has a bit of a bad habbit of ignoring the mime-type, or even the filename in the header of a file when you import it through importFileInto or setting the fileName property of a member in Shockwave. This means that it is not possible to load eg an image through a php script; Shockwave/Director only sees the .php extension it requested, and does not recognise that as an image format. As a result the image will not import. Since php is often used to 'glue' Shockwave movies to a database, this inability can be quite a problem. Personally, I am using PHP scripts to digest complex files into chunks that Shockwave can handle (ie: load embedded jpg frames from quicktime vr files).

One workaround is to use mod_rewrite (or similar) to fake an image on the server with the same name as the php script, but with an image extension. Let shockwave request the fake,non existent image and have mod_rewrite reroute the request to the php file. Director only sees the original filename it requested, and imports the result of the php script. This works fine, but getting mod_rewrite installed and configured may be tricky on a shared hosting environment. The least you should have is access to your .htaccess file, adding something like this:

RewriteEngine on
RewriteRule ^script\.jpg$ script.php

This will emulate a file named script.jpg, and reroute requests to that file to script.php

Joost Nieuwenhuijse showed me a neat trick that does not require mod_rewrite. Instead, it abuses Apache's support for 'slasharguments'. If you want to disguise a php script as a file with another extension, you can simply append a dummy file after the script name. Instead of


you would use


Note that script.php is not actually a folder, and no file named disguise.jpg exists. This syntax can be used to created cleaner urls in CMSes, in which case the 'arguments' after the slash are passed to the php script. In our case however, we happily ignore the argument, and the script is executed as normal. Shockwave however, knowing nothing about php, thinks /script.php/ is part of the path and only sees the disguise.jpg file name. As a result it will import the result of the php script as a jpg image.