Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Error reading image from perl cgi script into HTML

by fsn (Friar)
on Oct 13, 2002 at 12:32 UTC ( #204891=note: print w/replies, xml ) Need Help??


in reply to Error reading image from perl cgi script into HTML

As podmaster put's it, you have misunderstood some things about browsers, HTML and HTTP. You should make an html page which refers to you counter image like any other image. This could serve as a very simple (and untested) example:

First, the HTML page:

<html> <head> <title>Test page</title> </head> <body> <H1>My test page</H1> My counter below:<BR> <IMG SRC="/cgi-bin/my-count.pl"> </body> </html>

And now, my-count.pl

#!C:\Progra~1\Perl\bin\perl use CGI; $co=new CGI; print $co->header(-type=>'image/jpeg'); $size = stat("counter.jpg")[7]; open (FILEHANDLE,"<counter.jpg"); read FILEHANDLE,$imagedata,$size; close FILEHANDLE;
And then you replace my-count.pl with something that actually counts.

Replies are listed 'Best First'.
Re: Re: Error reading image from perl cgi script into HTML
by Anonymous Monk on Oct 13, 2002 at 23:02 UTC

    I tried exactly as fsn said. I also added BINMODE before the FILEHANDLE as BUU said. But it still does not work.

    Following is html file contents (mycounter.html)

    <HTML> <head> <title> Test page </title> </head> <BODY> <H> My test page</H> My counter below: <BR> <IMG SRC = "mycounter.cgi"> </BODY> </HTML>
    and Following is the contents of the perl cgi file (mycounter.cgi)
    #!C:\Progra~1\Perl\bin\perl use CGI; $co=new CGI; $size = stat("counter.jpg")[7]; open (FILEHANDLE,"<counter.jpg"); binmode FILEHANDLE; read FILEHANDLE,$imagedata,$size; close FILEHANDLE; print $co->header(-type=>'image/jpeg'), $imagedata;

    But the only thing I get when I open mycounter.html is the following string

    "My test page. My counter below:" followed by a blank image file.

    I have checked and the image file counter.jpg exists in the current directory. But why does the html display a blank image? If you could identify any other possible reasons for this it would be really appreciated.

    thanks grao5

      this happens sporadically with me and windows 2k. 
      I write to model/wrl files and sometimes the browser  
      doesn't render as it should. My fix is the following.
      (Keep your perl script as is with the binmode STDOUT statement in place.)
      In the html page type this:
      <img src="mycounter.cgi?itlooksstupidbutsozwindows.jpg">
      by ending my query string with anything.jpg or anything.wrl
      i was able to convince my browser to stop spordically 
      sending me non-text content as text.
      

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://204891]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2022-12-06 00:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?