I use file upload in Embperl without problems, can you post your form
and describe better (with code) the way you are handling %fdat to
retrieve the file?
oh boy. this is going to get nasty quickly. i'll try to a few code
sources without showing too much since the way i'm building my site is
kinda complex in structure. hopefully it'll be enough.
the main file containing the embperl form page is the one below. this file
mainly is used to capture the data and then send it off to the index.epl
page which contains the code for calling handler/controller object for
manipulating the %fdat and %udat variables. this page is just a view with
a few elements for displaying the results of either a lookup or after the
form is submitted for editing purposes.
Add/Edit Image
[$ if $fdat{msg}->{msg} $]
[+ $fdat{msg}->{msg} +]
[$ endif $]
[$ if defined $fdat{msg}->{data}->{image}->{id} $]
width="[+ $fdat{msg}->{data}->{image}->{width} +]"
height="[+ $fdat{msg}->{data}->{image}->{height} +]">
[$ endif $]
Load Image:
Image Type:
[-
$fdat{image_type_id} =
$fdat{msg}->{data}->{image}->{image_type_id}
if
$fdat{msg}->{data}->{image}->{image_type_id};
Execute('image_type_select.epl');
-]
Height:
Width:
[$ if defined $fdat{msg}->{data}->{image}->{id} $]
[$ endif $]
this next page is the controller kind of view which makes calls to
instantiate a controller object and hand the request and session
information to the controller object (as well as some customized
environment settings which is represented by the
$Apache::system->{config} and $Apache::ep references).
[-
use Handler::Controller;
my $controller = new Handler::Controller(
system => $Apache::system->{config},
event => $Apache::ep,
session => \%udat,
request => \%fdat
);
$fdat{msg} = $controller->process();
if (defined $fdat{msg}->{data}->{dude})
{
$udat{user} = $fdat{msg}->{data};
}
-]
[- Execute ('header.epl') -]
[- Execute ($fdat{msg}->{page}) -]
the next object is handles the request data and assembles it into hash refs
(or occasionally array refs depending on the application). I do this to
segregate my data so that I can send it to an appropriate data object for
persisting in my database. However, you'll note here that there is a piece
of code that says:
upload => $q->{upload} which represents the uploaded file.
package Builder::AddImage;
use Builder::Base;
use strict;
@Builder::AddImage::ISA = qw(Builder::Base);
sub init
{
my ($self, $class, %args) = @_;
$self->{image} = {};
}
sub build
{
my $self = shift;
my $q = $self->{request};
$self->{image} = {
id => $q->{id} || 0,
image_type_id => $q->{select_image_type},
height => $q->{height},
width => $q->{width},
upload => $q->{upload},
};
return 1;
}
1;
the file that writes the file to my server is the one below. i think it's
pretty close to how a lot upload scripts handle saving a file to the
server, except that i use an object to handle it.
package Utilities::Upload;
use strict;
sub new
{
my ($class, %args) = @_;
my $self = {};
$self->{file} ||= $args{file};
$self->{dest} ||= $args{dest};
bless $self, ref $class || $class;
}
sub upload
{
my $self = shift;
my $file = "$self->{dest}/$self->{file}";
unlink $file if -e $file;
open FILE, ">>$file" || die $!;
my $buffer;
my $totallength = 0;
my $bytes;
while( $bytes = read($self->{file}, $buffer, 1024) )