Re: Image display problem with CGI script
by PodMaster (Abbot) on Dec 12, 2003 at 14:14 UTC
|
sysread IMG, $img, -s IMG;
`perldoc -f -x'
| MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!" | | I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README). | | ** The third rule of perl club is a statement of fact: pod is sexy. |
| [reply] [d/l] |
Re: Image display problem with CGI script
by blahblahblah (Priest) on Dec 12, 2003 at 14:06 UTC
|
I tried your script on my windows 98 with perl 5.6.1 and apache 1.3.12, and IE 6, and it works for me. I modified only the hardcoded paths.
One tip: instead of just calling die, you ought to print out an error page.
I tried commenting out the line that you say is "doggy". When I do that, I get a little broken image box with the red x in IE. I couldn't figure out any way to make the script hang. | [reply] |
Re: Image display problem with CGI script
by Paulster2 (Priest) on Dec 12, 2003 at 13:59 UTC
|
Not that I know exactly what is going wrong here, but can you try running the script from the command line? I have found that by the output of the script (namely the HTML code that is produced) you can decipher where it is hanging and this will get you on the road to where you need to be.
I don't know if it will work in your case, because it looks like your running windows, but it's worth a try. Unfortunately I don't have the access between my two machines, this one and the one I can run Perl on, so I can't try it for you.
I hope that maybe this idea will help you decipher your problem. Other than that, get some sleep, it always helps!!
| [reply] |
|
|
Hi Paulster2, thanks for the comment on getting some sleep. ;-)
Yes that's exactly what I did soon after I posted the node. After a good night's sleep, I have found out what's wrong with my Apache server in the morning.
Well, *nothing* was wrong with Apache, it's the Windows XP that Apache runs on that caused the problem. I haven't rebooted the box for a week, the performance of Apache deteriorated gradually, and funny things began to appear.
I never have to worry about rebooting when I had the Linux box earlier. I have only rebooted once or twice when I relocate. So when I move the server on to a Windows box, I never had the habbit of rebooting the box. Now I begin to wonder if I made the right decision at all to move from Linux to Windows. But it's a bit late now that I have over 160GB of stuff stored on NTFS partitions, so I am thinking about getting a cheap PC and install linux on it, and use that as my web server, while still keeping the XP box as it is.
| [reply] |
|
|
The separate *nix box may make sense for you if you have the H/W. I needed to be portable _and_ have both WinXP and Linux, and so have VMWare installed to run Linux hosted on WinXP. I can duplicate my target environments (yes, plural) as needed. It is a very nice setup all in all.
| [reply] |
|
|
So, what you are telling me is that not only you needed some sleep, but the box did too??;-)
Believe me I understand about the Windows thing. I'm a Govie contractor who likes UNIX, but gets stuck working with PC's all the time. It got so bad after one install, I almost threw out my home PC! I am also thinking about building a Linux machine for home use. It would work great as a webhost of sorts (I think! Never used the Linux flavor, but love UNIX. I understand it's fairly transparent, within reason.) Glad you got your problem fixed! Hope to be seeing you around the PM site.
| [reply] |
Re: Image display problem with CGI script
by injunjoel (Priest) on Dec 12, 2003 at 17:53 UTC
|
Greetings all,
Just a quick question. Why are you opening the file in the first place? Since this is a CGI script I would bet you are viewing this script via a web browser in which case you could simply check for the existence of the file, if its there pass the path(url) to the browser else error out.
Just a thought since from looking at your code above you are not really doing anything with the image that requires reading it in binarily (is that a word?).
Of course I have not seen the rest of your code so I could be wrong.
-injunjoel | [reply] |
|
|
Hi injunjoel, that *is* the rest of the code. The images I want to display is stored under local directories, and I don't want to make the files accessible from the Web, I only want to access them via a CGI script, so I can control the access later. I put in the binary mode because the script was not running properly and I wanted to see if that would make any difference.
| [reply] |
Re: Image display problem with CGI script
by talexb (Chancellor) on Dec 12, 2003 at 18:13 UTC
|
print $cgi->header( -type=>'image/jpeg', -attachment=>$jpegFile);
open( JPEG, $jpegFile )
|| die "Unable to open $jpegFile for read: $!";
my $buffer;
while ( sysread( JPEG, $buffer, 65536 ) ) { print $buffer; }
close(JPEG);
--t. alex
Life is short: get busy!
Update: Corion and are disagree about whether a binmode is required .. anyone? Anyone?
Update 2: Corion pointed out that under Win32, binmode will be required .. but that's on the server, not on the client, since it's on the server that the CGI is being run. I forget that because I've been programming under Linux for the last five years -- binmode isn't required there. | [reply] [d/l] [select] |
|
|
Hi thanks talexb I think the problem is not with my script, but rather with my apache server, as I have just discovered. I invoked the cgi from another computer (other than the web server), I could see the images being properly displayed. Just that when I tried to access from the server box, the cgi hangs. So I am going to look a bit more into how my apache server was configured, hopefully that could give me more clue.
I have tried to add the attachement option to my script, and it still not work from the server, but it works from a differnet computer with or without the attachment option.
Thanks for the comment anyway. ;-)
| [reply] |
|
|
| [reply] |