Revision 3 (by ahitrov@rambler.ru, 2010/03/24 15:19:32) |
The CORE
|
<%ARGS>
$SETS => undef
$field => undef
$default => undef
$object => undef
</%ARGS>
<%INIT>
return undef if ( (! defined($SETS)) || (! defined($field)));
use vars qw($keeper);
# --------------------------------------------------------------------------------------
# ���������� ����� ��������
my $MULTI = $default;
if ($SETS->{ $field }) {
my $filename = '/binary/'.$object->get_file_name() || return;
my $filename_tmp = $state->{'tmp_dir'}.'/'.join('_', split('/', $filename));
my $upload = $r->upload($field);
if ($upload) {
my $extension = $upload->filename =~ /([^\.]+)$/i ? lc $1 : 'bin';
my $fh = $upload->fh();
my $size = (stat $fh)[7];
my $fh_tmp = IO::File->new('>'.$filename_tmp.'.'.$extension) || die 'Can\'t open temporary file';
my $buffer;
sysread $fh, $buffer, $size;
syswrite $fh_tmp, $buffer, $size;
undef $fh_tmp;
Contenido::File::store($filename.'.'.$extension, $filename_tmp.'.'.$extension);
unlink $filename_tmp.'.'.$extension if -e $filename_tmp.'.'.$extension;
$MULTI->{ext} = $extension;
$MULTI->{filename} = $filename.'.'.$extension;
$MULTI->{size} = $size;
} else {
warn 'ERROR in incoming POST form: "'.$field.' is not file upload (value: "'.$SETS->{$field}.'")';
}
}
# �������������� ���� - ����� ���, ��� ������...
my $pattern = '^'.$field.'\.(.*)$';
foreach my $localfield (keys(%{ $SETS }))
{
if ($localfield =~ /$pattern/)
{
my $multifield = $1;
$MULTI->{$multifield} = $SETS->{$localfield};
}
}
return $MULTI;
</%INIT>