I'm trying to read a file that is sent via the filefield field (redundant :-p)and I cannot get anything. I'm using CGI.pm hoping against hope that the upload() func would work, but it doesn't seem to give me anything. The file is coming from a WinDoze box and the cgi in on a linux box. Here's the code I'm using to test with.
#!/usr/bin/perl $DEBUG = 0; ######## use CGI; $query = new CGI; ######## $type = 'something/else'; print $query->header(); $ERROR = $query->cgi_error; $fh = $query->upload('$filename'); $filename = escapeHTML($query->param('attfile')); $type = $query->uploadInfo($filename)->{'Content-Type'}; unless ($type eq 'text/html') { die "HTML FILES ONLY!"; } if (!$fh) { print_html($ERROR); exit 0; } else { print_html("The file was of type ", $type); } if($DEBUG == 1) { @Everything = <$fh>; print_html(@Everything); } sub print_html { @String_To_Use = @_; $SizeOfArray = $#_; $Count = 0; print $query->start_html(); print "<CENTER>\n"; while($Count <= $SizeOfArray) { print "$String_To_Use[$Count]\n"; print "<BR>\n"; $Count++; } print "</CENTER>\n"; print $query->end_html(); }
The output I get is:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=Content-Type content="text/html; charset=windows-1252 +"></HEAD> <BODY></BODY></HTML>
The file that I'm inputting, ie the filefield is C:\filename.txt

Any help is greatly appreciated.

Thanx

Ryan Howerton

Edit 2001-03-13 by tye to remove <PRE>.


In reply to Reading a File Uploaded to a cgi script by rhowerton

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.