On Thu, 14 Nov 2002, Dennis Daupert wrote:
> I have gotten file upload working using Apache::Request for
> text files. But binary files seem to have other ideas :-)
>
> For example, uploading a word doc, I get a success message,
> but when I retrieve the doc after uploading it, and try to open it in
> Word 2000, I get the popup error message:
>
> "The document name or path is not valid... etc"
>
> Do I need to do anything to detect the content type of the file and
> set binary versus ascii transfers? The man page for Apache::Request
> talks about type, but not how to set the transfer.
>
> In case I have done something silly in my code, here is a section in which
> I untaint the filename, and also remove the leading c:\path\to\file info
> (for windows uploads) or similar /path/to/file for unix uploads:
[ .. ]
> And then:
> my $fh = $upload->fh;
> my @file = <$fh>;
> open ( WRITEFILE, ">$data{'write_dir'}/$data
> {'up_filename'}" ) or die "couldn't open $data{'up_filename'} for writing:
> $! \n";
> print WRITEFILE "@file";
> close (WRITEFILE);
For binary docs, would a
binmode WRITEFILE;
before the print statement help?
--
best regards,
randy kobes