Click to See Complete Forum and Search --> : Using images in PERL CGI Scripts


carteran
07-16-2006, 09:32 PM
Greetings,

I'm new to PERl in a CGI/web type context. I'm able to generate some images (graphs using rrdtools) using PERL but can't see how to deliver these images to a web page using a CGI script. I have formated the image placement using tables but the images refuse to display - only the placeholder. The only hint I could find was to use the content type as image/jpg but there was no example of how to use it.
Whats the best way to imbed images in web pages using PERL/CGI
Many thanks in advance.

robertketter
07-17-2006, 07:00 AM
Without seeing a snippit of code I can only guess you might be missing the correct path to the image you want to display. I always use the complete path or url to the image... ie: http://www.domain.com/images/image.jpg

Your code may have browsers looking in cgi-bin for image without correct path.
:confused:

carteran
07-17-2006, 06:41 PM
Thanks for the reply - here the test script I'm using. I have put the image in both the content directory (absolute path /var/www/html/images) and the cgi-bin directory but neither seems to deliver. Thanks in advance....

#!/usr/bin/perl

print "Content-type: text/html\r\n\r\n";
print "<HTML>\n";
print "<HEAD><TITLE>Monitoring Data</TITLE></HEAD>\n";
print "<BODY>\n";
print "<H2>Monitoring Data</H2>\n";
my $today = `date`;
print "$today\n";
print "<p><b><font size=+1>3PXSouth</font></b></p>";
print "<br>";
print "<table BORDER WIDTH=\"100%\" >";
#print "<table>";
print "<tr>";
print "<td><img SRC=\"/var/www/cgi-bin/clinker_built.jpg\" height=244 width=338 align=CENTER></td>";
print "<td><img SRC=\"/var/www/html/images/clinker_built.jpg\" height=244 width=338 align=CENTER></td>";
print "</tr>";
print "</table>";

print "</BODY>\n";
print "</HTML>\n";

exit (0);

carteran
07-17-2006, 06:54 PM
Jumped too soon with my reply. I tried **full** paths to the images using URLS of the form you suggested - works well. many thanks Robert.