in reply to Using GD in a CGI script to randomly select images fails...

A common mistake is to assume the current directory is the directory in which the script resides. If that's the case here, you could be attempting to load images which cannot be found.

One solution is to explicitely switch the current directory to the one containing the script.

use File::Basename qw( dirname ); use File::Spec::Functions qw( rel2abs ); BEGIN { chdir(dirname(rel2abs($0))); }

By the way, could you explain what exec $0 if not $imgStream; accomplishes (besides introducing a potential infinite loop)?

Replies are listed 'Best First'.
Re^2: Using GD in a CGI script to randomly select images fails...
by blue_cowdawg (Monsignor) on Aug 07, 2007 at 20:11 UTC
        If that's the case here, you could be attempting to load images which cannot be found.

    I thought of that.

    # further up in the code: my $dir = $ENV{HOME} . "/www/pix/gallery"; # this points to the only place we should be loading # images from. | | Loop through the directory and populate all the valid | file names into an array my $image=sprintf( "%s/%s",$dir,$imageStack[rand($top)]); # that picks a single name out of the list and prepends # the full path of the gallery directory to the name.
    At one point in my development of this script I did actually have a chdir to the gallery and eliminated it thinking there was some funky-delic permissioning issue going on with the server itself. The random selection code works. I'm just getting those nasty premature header ending errors.


    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg