++wog for getting you on the right track and ++tilly for explaining where and why the problem was arising.
I just thought that I would add this as an extra.
To help show what you can do with the "local" filename and why you might want it. Also, if you are using CGI.pm, you might aswell
use it.
#!/usr/bin/perl
use CGI;
$co = new CGI;
if (!$co->param()) {
print $co->header,
$co->start_html('upload a file'),
"<table border=1><tr><td>",
$co->center('upload a file'),
$co->start_multipart_form,
$co->filefield(-name=>'file1', -size=>30),
$co->br,
$co->submit(-value=>'Upload'),
$co->end_form,
"</td></tr></table>";
} else {
$file = $co->param('file1');
print $co->header,
$co->start_html('file uploaded'),
"Uploading $file ...<br>";
@filename = split(/\\/, $file);
open (FILE, ">safe/$filename[$#filename]"),
print "... $filename[$#filename] uploaded.";
print FILE <$file>;
close FILE;
}
print $co->end_html;
This is working, but of course, this script is JUST AN EXAMPLE, and you should not trust input forms. Use -T and check the file path for bad chars. Basic error checking, referrer checking, etc.
"Better secure than sorry." -xtype
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.