Dear Monks,
i know this has been covered many times, but the code i have is just freaking me out. I tried to do it with as few as possible lines, but it would still give me silly errors, i just cant understand why?!
here is the code, pls help if you can!
#!perl -wT
use CGI;
use CGI::Carp qw ( fatalsToBrowser );
use strict;
use Fcntl qw ( :DEFAULT :flock );
use constant UPLOAD_DIR => "c:/some/path/Admin/images/";
my $q = new CGI;
my $filename = $q->param('file');
my $fh = $q->upload('file');
$filename =~ s/[^\w.-]/_/g;
if ($filename =~ /^(\w[\w.-]*)/) {
$filename = $1;
}
else {
error($q, "Invalid file name." );
}
my $upload_dir = UPLOAD_DIR . $filename;
sysopen(OUTPUT, $upload_dir, O_CREAT | O_RDWR | O_EXCL);
my $buffer = "";
while (read($fh, $buffer, 16384)) {
print OUTPUT $buffer;
}
close OUTPUT;
print $q->header,
$q->start_html("At long last"),
$q->h1("done dude...doh"),
$q->end_html;
As it is now, this would throw an error like:
Can't use an undefined value as a symbol reference at C:/some/path/aga
+in.pl line 34.
or something like:
Error near ""binmode
Essentially i tried to follow the docs, made use of past posts here in <a href="www.perlmonks.org>perlmonks, with no apparent success though!!
Any help will do!!!
cheers
r_mehmed
novice
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.