Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

CGI, file upload and netscape 7

by aging acolyte (Pilgrim)
on Nov 20, 2002 at 11:28 UTC ( #214399=perlquestion: print w/ replies, xml ) Need Help??
aging acolyte has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am stumpted and submit myself to your mercy. I suspect my problem may be with my browser but I cannot pass a file upload parameter to my cgi script with the full directory path. The file parameter is always local to my cgi-bin and not the full path the documentation implies it should be. The code works in netscape 6. Any ideas? Thanks AA
#!/usr/bin/perl -w -T use strict; use CGI; my $entrypg=new CGI; print $entrypg->header, $entrypg->start_html( -title => "Load your file", -BGCOLOR => 'white', -LINk => 'red' ), $entrypg->center($entrypg->h1("Upload annotation file")), $entrypg->start_multipart_form( -name=>'form', -method=>'POST', -action=>'http://xyz.co.uk/cgi-bin/Parse.cgi' ), $entrypg->table( {-border=>'1', -align=>'CENTER', -cellspacing=> '1', -cellpadding=>'1', }, $entrypg->TR( {-colspan=>'2'}, "Please choose your file:" ), $entrypg->TR( $entrypg->td($entrypg->filefield( -name=>'INPUT', -size=>'50' ) ) ) ), $entrypg->submit, $entrypg->reset;
and Parse.cgi=
#!/usr/bin/perl -w -T use strict; use CGI; use Data::Dumper; use XML::Parser; my $xmlpg = new CGI; my $file = $xmlpg->param("INPUT"); my ($ID,$from, $to); my $p =new XML::Parser(Style=>'Tree'); my $doc = $p->parsefile("$file"); #print Dumper($doc); my $level =0; process_node(@$doc); sub process_node { my ($type, $content) = @_; if ($type eq 'id') { $ID = trim($content->[2]); } elsif ($type eq 'from') { $from = trim($content->[2]); } elsif ($type eq 'to') { $to = trim($content->[2]); } if ($type) { while (my @node = splice @$content, 1, 2) { process_node(@node) } } } sub trim { local $_ = shift; s/\n/ /g; s/^\s+//; s/\s+$//; return $_; } print $xmlpg ->header, $xmlpg->start_html( -title => "XML File", -BGCOLOR => 'white', -LINk => 'red' ), $xmlpg->h1("Looking at $ID which starts at $from and finishes at + $to");

Comment on CGI, file upload and netscape 7
Select or Download Code
CGI, file upload and netscape 7
by aging acolyte (Pilgrim) on Nov 21, 2002 at 11:57 UTC
    UPDATE:

    I have found a work around but not an ideal solution.

    The problem is that param("INPUT") is being read as a file handle and so causes problems when passed into XML::Parser.

    My solution is to write the open file into a tmp file and then pass that tmp file to the parser.

    Can anyone suggest a more elegant solution?

    Thanks again

    AA

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2014-11-23 19:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (134 votes), past polls