Line # Revision Author
1 8 ahitrov@rambler.ru <%ARGS>
2
3 $SETS => undef
4 $field => undef
5 $default => undef
6 $object => undef
7
8 </%ARGS>
9 <%INIT>
10
11 return undef if ( (! defined($SETS)) || (! defined($field)));
12 use vars qw($keeper);
13
14 # --------------------------------------------------------------------------------------
15 # Добавление одной картинки
16 my $MULTI = $default;
17
18 if ($SETS->{ $field }) {
19 my $filename = '/binary/'.$object->get_file_name() || return;
20 my $filename_tmp = $state->{'tmp_dir'}.'/'.join('_', split('/', $filename));
21
22 my $upload = $r->upload($field);
23 if ($upload) {
24 my $extension = $upload->filename =~ /([^\.]+)$/i ? lc $1 : 'bin';
25 my $fh = $upload->fh();
26 my $size = (stat $fh)[7];
27
28 my $fh_tmp = IO::File->new('>'.$filename_tmp.'.'.$extension) || die 'Can\'t open temporary file';
29 my $buffer;
30 sysread $fh, $buffer, $size;
31 syswrite $fh_tmp, $buffer, $size;
32 undef $fh_tmp;
33
34 Contenido::File::store($filename.'.'.$extension, $filename_tmp.'.'.$extension);
35 unlink $filename_tmp.'.'.$extension if -e $filename_tmp.'.'.$extension;
36
37 $MULTI->{ext} = $extension;
38 $MULTI->{filename} = $filename.'.'.$extension;
39 $MULTI->{size} = $size;
40 } else {
41 warn 'ERROR in incoming POST form: "'.$field.' is not file upload (value: "'.$SETS->{$field}.'")';
42 }
43 }
44
45 # Дополнительные поля - берем все, что найдем...
46 my $pattern = '^'.$field.'\.(.*)$';
47 foreach my $localfield (keys(%{ $SETS }))
48 {
49 if ($localfield =~ /$pattern/)
50 {
51 my $multifield = $1;
52 $MULTI->{$multifield} = $SETS->{$localfield};
53 }
54 }
55
56 return $MULTI;
57
58 </%INIT>