Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

CGI Trying to save file to computer rather then display it in browser

by stuffy (Monk)
on Apr 29, 2001 at 13:34 UTC ( #76455=perlquestion: print w/replies, xml ) Need Help??

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

I have what shlould be a simple script that I am writing for our intranet at work. I am Posting information, it processes it, then it is supposed to show the output on the screen. Instead I am getting a dialog box asking to save the file. I am unable to use CGI due to the fact that it is not loaded on the server, and I do not have enough room in my personal directory for a local copy with all the other stuff I have in there. Here is the part in question:
print "Content-type:test/html\n\n"; print "<HTML>\n"; print "<BODY>\n"; while (<INPUTFILE>) { if (/^(.*?)$tool_number(.*)$/{ ($continue) =1; } if (/^(.*?)$end_tool(.*)$/ { ($continue) = 0; } if ($continue ==1){ print "some stuff\n"; } }
I would include the rest of the code.....but I'm not a very good programmer, and It would get hacked to heck. Plus it is related to my work....gotta love those "created at work" clauses.
  • Comment on CGI Trying to save file to computer rather then display it in browser
  • Download Code

Replies are listed 'Best First'.
Re: CGI Trying to save file to computer rather then display it in browser
by olly (Scribe) on Apr 29, 2001 at 13:43 UTC
    I am always a bit puzzled by the reasons m scripts are offered for download all of a sudden, but I maybe it has something to do with the content-type which you have set to test/html. I have never seen it before. Could it be the correct line should be
    print "Content-type: text/html\n\n";

    Just a guess.

    Imagination is more important then knowledge -Einstein-

      I am always a bit puzzled by the reasons m scripts are offered for download all of a sudden, but I maybe it has something to do with the content-type which you have set to test/html. I have never seen it before. Could it be the correct line should be print "Content-type: text/html\n\n";

      This error might have been avoided by using CGI.pm like so:

      #/usr/local/bin/perl -wT use strict; use CGI qw(:standard); print header, start_html(-title=>'My Neat Program'), print end_html;
      The header shortcut by default spits out "Content-type: text/plain"
        The header shortcut by default spits out "Content-type: text/plain"
        No, actually "print header" in CGI.pm spits out "Content-type: text/html." You can get CGI to produce text/plain if you want (or any other MIME type for that matter) but text/html is the default.

        Gary Blackburn
        Trained Killer

      Talk about feeling stupid. Maybe I should find a good editor to proof my scripts. Thanks alot. I looked it over and over, but I couldn't see that. Kind-a like the real part of my job, (the scripting thing is extra)sometimes it takes another set of eyes.
Re: CGI Trying to save file to computer rather then display it in browser
by eejack (Hermit) on Apr 30, 2001 at 03:35 UTC
    This may sound like a goofy point, but I usually cut and paste very common boilerplate bits like this because of my constant fat finger errors.

    The two that always seem to bite me
    #! /usr/bin/perl
    works fine on the command line 'cause usually I am calling
    perl somescript.cgi
    but blows up in the browser. Drives ya nuts until you find the space between the shebang and the first /

    The other one...saving files in PC format (see lots of control M) instead of unix format whilst working across platforms.

    One of these days instead of spell checker I will have to work on a *goofy going to cost you fifteen minutes of hair pulling time* checker.

    EEjack

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2021-10-26 09:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (90 votes). Check out past polls.

    Notices?