Em Fri, 10 Jan 2003 00:32:55 +0900
Keith Watanabe <[EMAIL PROTECTED]> escreveu:

Hi,

Embperls handles file uploads trough CGI.pm this way when you use
"multipart" forms the file fields are converted in file handles.

In the code bellow it seems that your are reading from the wrong
variable in your object:

> sub upload
> {
>           my $self = shift;
>           my $file = "$self->{dest}/$self->{file}";

If in $self->{file} you have the "upload" field of the form you should
not use it here this way since it doen not contain just the filename.
In my code I apply the following regex (for a true portable solution you
should use File::Basename):

if ( $fdat{file} =~ /([^\/\\]+)$/ ) {
  my $filename = $1;
  $filename =~ s/^\.+//; # To prevent hidden files
}

>           unlink $file if -e $file;
>           open FILE, ">>$file" || die $!;
>           my $buffer;
>           my $totallength = 0;
>           my $bytes;
>           while( $bytes = read($self->{file}, $buffer, 1024) )

You have to be sure that in $self->{file} you are really reding from
a reference to $fdat{upload} since its there the magic with CGI.pm.
If you transformed the data it will not work since it will not be a
filehandle anymore. If you need to check and transform the "upload"
field to convert it in a filename you should store a reference to
$fdat{upload} in another instance variable of your object to read from
it later.

>           {
>                  print FILE $buffer;
>                  $totallength += $bytes;
>           }
>           close FILE;
>           close $self->{file};
> }

Regards,

Luiz Fernando B. Ribeiro
Engenho Soluções para a Internet

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to