/[Arh]/lib/Arh/Action/UploadPicture.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /lib/Arh/Action/UploadPicture.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 48 - (hide annotations)
Sun Apr 6 16:09:03 2008 UTC (16 years, 1 month ago) by dpavlin
File size: 1282 byte(s)
cleanup and tweaks for filename to endup in database
1 dpavlin 44 use strict;
2     use warnings;
3    
4     =head1 NAME
5    
6     Arh::Action::UploadPicture
7    
8     =cut
9    
10     package Arh::Action::UploadPicture;
11     use base qw/Arh::Action::CreatePicture/;
12    
13     use Data::Dump qw/dump/;
14    
15     =head2 take_action
16    
17     =cut
18    
19     sub take_action {
20     my $self = shift;
21    
22     if ( my $fh = $self->argument_value('content') ) {
23    
24     my $filename = scalar( $fh );
25     $filename =~ s/^.*([\/\\])([^\1]+)$/$2/;
26    
27     local $/;
28     binmode $fh;
29     my $content = scalar <$fh>;
30    
31 dpavlin 48 if ( $filename !~ m/\.(jpg|jpeg|png|gif|tif|tiff)$/i ) {
32     $self->result->error("unknown file type $filename");
33     return;
34     }
35    
36 dpavlin 44 warn "## $self take_action filename: $filename (", length($content), " bytes)\n";
37    
38 dpavlin 48 $self->argument_value( 'filename' => $filename ); # needed for report_success
39 dpavlin 44 $self->argument_value( 'content' => $content );
40    
41 dpavlin 48 my $id = $self->SUPER::take_action( @_ );
42    
43     # update database with correct filename (why do I need this?)
44     $self->record->set_filename( $filename );
45    
46     return $id;
47    
48     } else {
49     $self->result->error("No file uploaded!");
50 dpavlin 44 }
51    
52     }
53    
54     =head2 report_success
55    
56     =cut
57    
58     sub report_success {
59     my $self = shift;
60     $self->result->message( 'Created ' . $self->argument_value('filename') . ' with ' . length( $self->argument_value('content') ) . ' bytes' );
61     warn "## report_success ", dump( $self->result );
62     }
63    
64     1;
65    

  ViewVC Help
Powered by ViewVC 1.1.26