Hello all

I have a CGI script where a user indicates the location of an XML file on the file system through a form. On submission, the script should upload the file and store it in a database. At present, it seems to get all the correct information from the form but doesn't get the contents of the file. Here is what I have so far:

The relevant HTML form:

<p> Upload the file: <input type="file" name="upload_file"> </p>

The part of the code to get the file:

my $filename = $this->cgi()->param('upload_file'); my $xml = _upload_file($filename); sub _upload_file { my $filename = shift; my $file_contents = ""; my $buffer; while ( read($filename, $buffer, 1024) ) { $file_contents .= $buffer; } return $file_contents; }

At a guess it is because the $filename does not contain the full path to the file? However, I've seen the same code work in another program as is (I just cut'n'pasted it!). Furthermore, if I do need the full path, how do I get it from the HTML form?

Thanks.


In reply to Uploading files: can't find contents? by ezekiel

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.