What seems like a trivial problem, has had me stumped for nearly 24 hours already. Not only that, but without any proper documentation (the CGI.pm perldoc doesn't help much), I'm about ready to start pulling out hairs (furthermore, I hate posting seemingly easy problems to this great board... oh well).
What I'm trying to do is open an uploaded file for reading using an HTML form. Here's what happens on the server though: I can only read the file when it's already there!! That is, if I actually just copy my test file into the appropriate folder on the server, my script has no probs munching it up, but for some reason, it won't do it with an uploaded file using the form. What this means (I think), is that there's a problem with the way my code handles the upload. Here's a snippet of the relevant parts:
my $filename = $q->param("file");
my @data_from_file = get_file_data($filename);
sub get_file_data
{
my ($filename) = @_;
open (INPUTFILE, UPLOAD_DIR . $filename) || die "Can't open $filename"
+;
my @data_from_file;
while (<INPUTFILE>) {
push @data_from_file, $_;
}
close (INPUTFILE) || die "Can't close $filename";
unlink (UPLOAD_DIR . $filename) || die "Can't delete $filename";
return @data_from_file;
}
Any ideas? The server logs show no errors by the way, nor does my debugger. Also, I happenned to come over some code that recommended using the upload() function instead of param(). I tried that (perhaps incorrectly though), and it didn't work either.
I would be greatful for any comments! I love you guys! :)
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.