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

Hello esteemed monks,

I'm having an image problem with CGI. Essentially I cannot display the image. I checked the Apache logs and saw the following error:

(8)Exec format error: exec of 'gnuplot2.gif' failed, referer: test.cgi

Here is the code for 'test.cgi':

#!/usr/bin/perl -wT use strict; use CGI; my $cgi = new CGI; print $cgi->header(); print $cgi->start_html(qq(Image practice)); print $cgi->img( {-SRC=> 'gnuplot2.gif', -ALIGN=> 'left'}, qq(There should be an image in here somewhere) ); print $cgi->end_html();

To test the validity of the image file 'gnuplot2.gif', I placed it in an HTML document and it works (but only when its in the same directory as the HTML document calling it).

I'm not quite sure what's going on here. This is being developed on a standard LAMP server. Any ideas will be greatly appreciated.

Replies are listed 'Best First'.
Re: Image problem with CGI [ (8)Exec format error ]
by Fletch (Bishop) on Jun 05, 2007 at 14:09 UTC

    Your image file is in a directory which Apache is configured to execute CGIs from and apparently has permissions bits such that it's trying to execute the image. This quite unsurprisingly fails.

    Move the image file out of the CGI directory into a "plain" document directory (and adjust the URL in the src attribute accordingly), or remove execute permissions from the gif file.

Re: Image problem with CGI [ (8)Exec format error ]
by Moron (Curate) on Jun 05, 2007 at 14:14 UTC
    the src parameter should be a URL reference to the image, which of course can be a file system reference but you've given a bare filename.
    __________________________________________________________________________________

    ^M Free your mind!

      Thanks folks.

      Trouble was I did not really understand Apache's document structure. I do now :)

      I moved the file to a temp directory and accessed it from there. Now it looks (and works) like this:

      #!/usr/bin/perl -wT use strict; use CGI; my $cgi = new CGI; print $cgi->header(); print $cgi->start_html(qq(Image practice)); print $cgi->img({-SRC=> '/temp/nelo/gnuplot2.gif', -ALIGN=> 'left'}); print $cgi->end_html();