Dear Perl Monks,
I'm trying to use CGI::Upload to upload a file from the client to a
dir on the webserver
but can't seem to get it to work. The file gets opened and I can write
to it by sending a
simple test string. Everything returned from the upload object looks
fine. The problem as far as I can see is the file handle returned
below into $fh (type IO::File=GLOB)
is empty. So what I get when I run this is a 0 length file. Could it
be something to do
with Mime types ? I'm not sure what to do with this method:
mime_magic('/path/to/mime.types').
Should I give this method a list of valid mime types ? I'm not doing this.
Thanks in advance for any help.
Here are the particulars regarding my platform:
OS: XP Pro w/ SP1
Webserver: IIS v5.1
ActivePerl: v5.8.0.0.806
CGI-Upload: v1.05
Use statements:
use CGI qw(:standard table*);
use CGI::Upload;
Start form call:
print $q->startform(-method=>'POST',-action=>$q->self_url,
-name=>'editform',-enctype=>'multipart/formdata');
File field call:
print $q->filefield(-name=>'src',-override=>1,-maxlength=>100);
Subroutine:
sub fileupload {
my $upload = CGI::Upload->new;
my $fname = $upload->file_name('src');
my $file_type = $upload->file_type('src');
$upload->mime_magic();
my $mime_type = $upload->mime_type('src');
my $fh = $upload->file_handle('src');
$abfile = "c:\\Inetpub\\wwwroot\\images_test\\test_bill.jpg" ;
open (OFH, ">$abfile") or die "Error: File $file_name Upload: $!\n";
while(read($fh, $data, 1024)) {
print OFH $data or die "Error writing: $!\n";
}
close OFH;
}
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.