LostS has asked for the wisdom of the Perl Monks concerning the following question:

OK Guys,

Boss just pissed me off by saying he wants this random image display working in his PHP page... PHP does not support SSI. So umm I am wondering what would be the process of reading in an image file into perl and then outputing the binaries (the image)... you know instead of using SSI just have the image link point to the perl script...

Any help??
Billy S.

Replies are listed 'Best First'.
Re: Random Image Displayer
by suaveant (Parson) on Aug 09, 2001 at 21:52 UTC
    You could point an IMG SRC to a perl script which did...
    ... code to get random image name ... open(IMG, $img) or die $!; print "Content-type: image/jpeg\n\n"; #or gif, png whatever it is { local $/; print <IMG>; } close IMG;
    or you could have a perl script running that changed a symbolic link every few seconds, and just IMG SRC that link (much less processor intensive, but doesn't change for EVERY page load...)

                    - Ant
                    - Some of my best work - Fish Dinner

      I tried your suggestion... and I swear the server configuration is FUBAR... I am about to just get up and leave this job.

      Billy S.

        This isn't PHPMonks, but just so you know - you can execute or include the script in PHP just like you can in SSI. To include a file, do <?include "file"?>, and to execute it, use backticks or system() as you would in perl.

        to bad there is not a shove array function in perl... you could submit this to your superiors...
        shove @it, 'this job';

                        - Ant
                        - Some of my best work - Fish Dinner

Re: Random Image Displayer
by arturo (Vicar) on Aug 09, 2001 at 22:33 UTC

    minor blasphemy :

    Here I'd recommend learning a little PHP; it will be easier from a maintainability perspective than writing a utility in another language. PHP does not support SSI, but that's not a problem because its capacities exceed those of SSI by a big margin. PHP can output HTML, and that includes dynamically generating <img> tags. It can read directories, and filter on extension, and select a random one from among the list of matching files.

    Why bother spawning a whole new process when you have the capability already built in? The relevant functions in PHP are quite similar to the ones in Perl. Read up on readdir in PHP, learn how to use ereg_match, and you'll be able to write the image randomizer easily.

    perl -e 'print "How sweet does a rose smell? "; chomp ($n = <STDIN>); +$rose = "smells sweet to degree $n"; *other_name = *rose; print "$oth +er_name\n"'