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

Hi Monks, I have written a cgi script that writes a clickable image. I am running the cgi on a windows machine and I am having problems when it comes to displaying the images.

The images used to open up fine but now with the unchanged script(!) they wont open (e.g. the when you click on the image it seems to be looking for it in a different location to where it actually is.

The files are written to http://bioinf/~gb130/cgi-bin/ but clicking on the image looks for the files in C:\Documents and Settings\gb130\Local Settings\Temporary Internet Files\Content.IE5\4949AFKX\21.png and I have no idea why!?

If someone could look at my script to suggest how I can get the image to point to the correct location i would be grateful!

my $link = "error.html"; my $count =0; my @poss_numbers; $plot = plot_graph (\@temps, \@new, $well_no, $maxx, $maxx2); push @graph_links, $plot . ' '; push @existing_wells, $well_no . ' '; my $graph_links = join ('', @graph_links); @graph_links = split (/\s+/, $graph_links); my @graph_links2; my $m = 1; foreach my $a (@graph_links) { my ($n); if ($a =~ m/(\w{4})(.{1})(\d{1,2})(.{1})(\w{3})/) { $n = $3; } while ($n > $m) { push @graph_links2, "error.html"; $m++; } push @graph_links2, $a; $m++; } my @coords = ( undef, [53,46,22], [92,45,24],[131,48,21], [171,47,22], + [211,47,22],[248,47,22], [289,47,21],[327,47,21],[366,48,21],[406,46 +,23], [444,47,20],[485,48,21],[52,86,22],[92,86,22], [131,86,22],[171 +,86,22],[210,85,22],[249,86,22],[288,86,23], [327,85,24],[366,86,22], +[406,86,22], [445,86,22],[483,85,23],[54,125,22],[93,125,23], [131,12 +4,23],[170,125,22], [210,125,22],[249,125,23],[288,125,22],[327,124,2 +3], [367,125,24],[445,320,22],[483,320,21]); my $img; my $pos =0; for my $counter (1 .. 97) { if (defined $existing_wells[$pos] and $existing_wells[$pos] +== $counter) { # print "Use image: $counter \n"; $img = $graph_links[$counter-1]; $pos++; } else { # print "Use error image $counter\n"; $img = "error.html"; } # print $img; my $coords = join ',', @{$coords[$counter]}; print qq(<area href="http://bioinf/~gb130/cgi-bin/$img" ALT="" shape="circle" coords="$coords" target="_blank" width=300 height= +300></a>); } #---------------------- sub plot_graph { my ($temps, $numbers, $well_no, $maxx, $maxx2) = @ +_; my @graph_data = (\@$temps, \@$numbers); + my $graph = GD::Graph::lines->new (650, 400); $graph->set_legend("Melting temps: PEAK 1 - $maxx + PEAK 2 - $maxx2"); $graph->set_legend_font(GD::gdMediumBoldFont); $graph->set( x_label => 'Temperature degrees C', y_label => 'Fluorescence Derivative', x_max_value =>95, y_max_value =>0.7, title => "The derivative melting curve fo +r well $well_no", legend_placement => 'BC', x_label_position =>1/2, x_tick_number =>20, y_tick_number =>10 ) or die $graph->error; $graph->set (dclrs=> [qw(green red blue)]); my $gb = $graph->plot(\@graph_data) or die $graph- +>error; open (IMG , ">temp/$well_no.png") or die $!; binmode IMG; print IMG $gb->png; close IMG; my $plot = "temp/$well_no.png"; return $plot; }

Replies are listed 'Best First'.
Re: clickable image question
by fglock (Vicar) on Jun 25, 2003 at 17:26 UTC

    It looks like the browser is looking for the image in the browser's cache.

    You can check this by emptying the cache and pressing reload.

    If it works, then you can fix this in your cgi program by sending a 'no-cache' header.

Re: clickable image question
by tilly (Archbishop) on Jun 26, 2003 at 06:16 UTC
    Following up the previous answer, occasionally browsers refuse to acknowledge a no-cache request. In that case you can fool them by adding a unique ID (eg the time) to the request. That makes the browser see a new URL each time, so it will continue to request it properly.

    No, this is not a good thing to do. But sometimes bad things are necessary...