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

Hi, I am having trouble getting the enviroment ($ENV) varaibles to appear when I save the cgi with image/png format. Here is a snippet so you know what I mean:
print "Content-type: image/png\n\n"; open(RAW, "output.png"); binmode(RAW); print RAW $im->png(); while ( read( RAW, $buffer, 16_384 ) ) { print $buffer; } close(RAW);
Before In the cgi script I create an image with GD and I use a ENV variable. Why doesnt this work Thanks, Mello a continutation of this http://perlmonks.com/index.pl?node_id=414908 beacuse no-one was replying

Replies are listed 'Best First'.
Re: enviroment variables do not work when cgi saved as image/png
by r34d0nl1 (Pilgrim) on Dec 17, 2004 at 20:26 UTC
    Could you try to send us the complete code? I don't see where you are trying to use the ENV
    variables but it's very strange once that the ENV variables should became acessible during
    the entire execution of your script. Thanks
Re: enviroment variables do not work when cgi saved as image/png
by steves (Curate) on Dec 18, 2004 at 14:55 UTC

    If this works from the command line, but not as a CGI, and the issue is missing environment variables, I would first check your web server. You have to take special measures (i.e., configuration) to have a web server set environment variables that a CGI sees. The simple place to start is to write a CGI script -- not even necessarily Perl -- that shows what your environment is when the CGI is invoked. Apache comes with this printenv CGI script (written in Perl of course!):

    #!/usr/local/bin/perl ## ## printenv -- demo CGI program which just prints its environment ## print "Content-type: text/plain\n\n"; foreach $var (sort(keys(%ENV))) { $val = $ENV{$var}; $val =~ s|\n|\\n|g; $val =~ s|"|\\"|g; print "${var}=\"${val}\"\n"; }

Re: enviroment variables do not work when cgi saved as image/png
by sasikumar (Monk) on Dec 20, 2004 at 07:02 UTC
    Hi
    I hope the problem with the environment variables is because
    you would require to specify them in the httpd.conf
    (sorry i assume you would use the apache httpd server).
    just refer http://httpd.apache.org/docs/mod/mod_env.html

    beacuse no-one was replying
    Please post every question or doubt as a seperate node.

    Thanks Sasi Kumar