ezekiel has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
•Re: Uploading files: can't find contents?
by merlyn (Sage) on Apr 04, 2003 at 00:53 UTC | |
by tachyon (Chancellor) on Apr 04, 2003 at 01:01 UTC | |
by merlyn (Sage) on Apr 04, 2003 at 01:03 UTC | |
by maksl (Pilgrim) on Apr 04, 2003 at 15:22 UTC | |
by jasonk (Parson) on Apr 04, 2003 at 15:24 UTC | |
|
Re: Uploading files: can't find contents?
by jasonk (Parson) on Apr 04, 2003 at 00:50 UTC |