Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

File Uploading: IE vs. NS

by mojobozo (Monk)
on Nov 13, 2002 at 15:10 UTC ( #212605=perlquestion: print w/ replies, xml ) Need Help??
mojobozo has asked for the wisdom of the Perl Monks concerning the following question:

Hi!
I've got a nifty little file upload script that works just fine in IE. It's a wonderful thing. But I just tried it in Netscape and while it IS saving the file to the directory specified, it's also bringing up a "save as..." box so the user can save the upload.cgi to their harddrive. It's doing that instead of loading the HTML code as specified by the &subs which basically load a page saying that the file was uploaded. I've not run into this before and since most of the users I'm going to be dealing with HAVE to use Netscape, it's a problem I need a solution to.
Here's the code I'm using on the .asp page for the form:
<form method=post action=upload.cgi name=upload_epic enctype="multipar +t/form-data"> <input type=file size=20 name=upload> <br><input type=submit value=submit> </form>

And here's the code for the script (not entirely my own and minus the subs containing HTML code):
#!/usr/local/bin/perl use CGI qw/:standard/; use File::Basename; &print_return_page_top; print_results(); sub print_results { my $q = new CGI; my $length; my $file = $q->param('upload'); my $time = time; if (!$file) { print "No file uploaded."; return; } ($base,$path,$type) = fileparse($file,'\..*'); my $uploaded_path = "\\path\\to\\uploaded_files\\"; $uploaded_path .= $base; $uploaded_path .= "_"; open FILE, ">$uploaded_path$time$type"; binmode FILE; while ($bytesread=read($file,$buffer,1024)) { print FILE $buffer; } print h2('Success!'),"$file has been uploaded."; } &print_return_page_bottom;

If anyone could give me some insight as to why Netscape is puking this back up, it would be much appreciated. Thanks!
_____________________________________________________
mojobozo
word (wrd)
interj. Slang. Used to express approval or an affirmative response to
something. Sometimes used with up. Source

Comment on File Uploading: IE vs. NS
Select or Download Code
Re: File Uploading: IE vs. NS
by Mr. Muskrat (Abbot) on Nov 13, 2002 at 15:50 UTC

    Could it be fixed by the following line?
    use CGI qw/:standard :netscape/;

    I only ask because the docs for CGI say that :netscape "Import all methods that generate Netscape-specific HTML extensions."

    I haven't had the time to actually try this. It may be as simple as generating different headers...

Re: File Uploading: IE vs. NS
by fruiture (Curate) on Nov 13, 2002 at 15:53 UTC

    What does print_return_page_top() do?

    Did you test this on the commandline?

    Netscape isn't Netscape. Which Betscape are you using?

    --
    http://fruiture.de
Re: File Uploading: IE vs. NS
by tachyon (Chancellor) on Nov 13, 2002 at 15:54 UTC

    First as you are using CGI in exported function and OO mode which is problematic. You should use one or the other.

    You have not shown us where you are (? not) outputing a valid header that lets the browser know that this is html to display. You can use CGI.pm's header() method. Try this:

    #!/usr/local/bin/perl use CGI qw/:standard/; use File::Basename; print header(); print_return_page_top(); print_results(); print_return_page_bottom(); ### subs ### sub print_results { my $file = param('upload'); my $time = time; unless ($file) { print h2("No file uploaded."); return; } ($base,$path,$type) = fileparse($file,'\..*'); my $uploaded_path = "\\path\\to\\uploaded_files\\"; $uploaded_path .= $base; $uploaded_path .= "_"; open FILE, ">$uploaded_path$time$type"; binmode FILE; while(read($file,$buffer,1024)) { print FILE $buffer; } print h2('Success!'), p("$file has been uploaded."); } sub print_return_page_top { print h1('Top of page') } sub print_return_page_bottom { print h3('Footer') }

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

      It twas the "print header();" line that did it.
      Thanks!
      _____________________________________________________
      mojobozo
      word (wrd)
      interj. Slang. Used to express approval or an affirmative response to
      something. Sometimes used with up. Source
Re: File Uploading: IE vs. NS
by Abigail-II (Bishop) on Nov 13, 2002 at 16:01 UTC
    Netscape will only display HTML code if Netscape has been told it's HTML. (Quite surprisingly, Netscape follows the standard - that must have been by accident). You have to tell on the browser what the content-type of the document is, by issueing the correct HTTP header. CGI.pm has functions for that (although you could print them yourself). But that vital piece of code is missing from your code fragment (which only includes code that's totally irrelevant for the question).

    Abigail

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2014-09-20 18:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (160 votes), past polls