Forum Moderators: coopster & phranque

Message Too Old, No Replies

script works correctly with method=get but not with method=post. Why?

Script creates png image like its suppose to with "get" but not with "post"

         

warrior01

7:41 pm on Jun 29, 2005 (gmt 0)

10+ Year Member



I have a script that will create a png image using the values a user entered in a html form. The script works fine and creates a png image like its suppose to when I use method="get". But when I use method="post", it creates a bmp image. Why?

I'll post the code for both the form and the script below. If anyone spots the error, please do let me know.

aa.pl


#!/usr/bin/perl
print "Content-type: text/html\n\n";
use CGI::Carp qw{fatalsToBrowser};
use CGI;
use GD;
my $q = new CGI;
my $text = $q->param("text");
my $c1 = $q->param("c1");
my $c2 = $q->param("c2");
my $c3 = $q->param("c3");
my $img = GD::Image->new(400,90);
my $white = $img->colorAllocate(255,255,255);
my $color = $img->colorAllocate($c1,$c2,$c3);
my $font = "/home/username/Fonts/Verdana.ttf";
$img->stringFT($color, $font, 24, 0, 5, 80, $text);
print $img->png;

html form


<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<form method="post" action="/a/aa.pl">
<table cellpadding="4" cellspacing="2" border="1">
<tr>
<td>Text: </td>
<td><input type="text" name="text" size="4"></td>
</tr>
<tr>
<td>Color: </td>
<td>R: <input type="text" name="c1" size="1"> G: <input type="text" name="c2" size="1"> B: <input type="text" name="c3" size="1"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" value=" Go "></td>
</tr>
</table>
</form>
</BODY>
</HTML>

ckarg

7:49 pm on Jun 29, 2005 (gmt 0)

10+ Year Member



Shouldn't line 2 of aa.pl be something like:

print "Content-type: image/png\n\n";

Also some (older?) browsers might still be confused because a .pl url comes back with image/png content.

You may want to skip 'print' ing your own header, and use the CGI.pm header() function. See perldoc CGI.pm

moltar

7:58 pm on Jun 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You also might want to set your STDOUT to binmode if you are testing on win32.

binmode(STDOUT);

So the correct sequence of events should be like this:

print $q->header('image/png'); 
binmode(STDOUT);
print $img->png;

warrior01

10:39 pm on Jun 29, 2005 (gmt 0)

10+ Year Member



tried both your suggestions but nothing works unfortunately. Could it be that there's nothing wrong with the code but that my host has too old modules installed or something?