1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
#!/usr/bin/perl use strict; use CGI qw(-private_tempfiles); use File::Copy; $CGI::POST_MAX = 40_000_000; my $c = CGI->new; my $old = '/var/tmp/my $fh'; my $new = '/Fileserver/Frederik/my $fh'; if($c->param) { print $c->header(-charset => 'utf-8'), $c->h2('Result'); my $fh = $c->param('upfile'); # Get the FileHandle from temp-File printf qq(<p>Dateigröße: %s Bytes, Name der Tmp-Datei: %s</p>), -s $fh, $c->tmpFileName($fh); # Weitere Informationen aus uploadInfo print "<pre>"; foreach my $k(keys %{$c->uploadInfo($fh)}){ printf "%-25s => %s\n", $k, $c->uploadInfo($fh)->{$k}; } print $c->start_form, $c->button(-name => 'backbutton', -value => 'Zurück', -onclick => "location.href='/Admin/CGI/upload.pl'"), $c->button(-name => 'startpage', -value => 'Zurück zum Fileserver', -onclick => "location.href='/'"), $c->end_form; print "</pre>"; system ("cp $old, $new"); close $fh; } else{ # Erzeuge das Upload-Formular print $c->header(-charset => 'utf-8'), $c->h2('send a file'), $c->start_form( -enctype => 'multipart/form-data'), $c->filefield(-name => 'upfile'), $c->submit(-name => 'upload', -value => 'Datei hochladen'), $c->reset(-name => 'clear', -value => 'Feld löschen'), $c->button(-name => 'back', -value => 'Zurück zur Konfiguration', -onclick => "location.href='/Admin'"), $c->end_form; }
Quote/Fileserver/Frederik/$fh
Quote/Fileserver/Frederik/directory
system ("cp $old, $new");
copy( $old, $new );
QuoteOn Unix systems, the -private_tempfiles pragma will cause the temporary file to be unlinked as soon as it is opened and before any data is written into it
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
use CGI qw(-utf8); $CGI::POST_MAX = 40_000_000; use File::Copy; use File::Basename; my $c = CGI->new; if($c->param){ print $c->header(-charset => 'utf-8'), $c->h2('Result'); my $fh = $c->param('upfile'); # Get the FileHandle from temp-File my $source = $c->tmpFileName($fh); # get the source filename my $dest = $fh; # scalar context, origin filename from UserAgent my $ref = [fileparse($dest)]; # Dateiname in [0] print "Copy $source, /tmp/$ref->[0]"; copy $source, "/tmp/$ref->[0]"; }
QuotePROCESSING A FILE UPLOAD FIELD Basics
1 2 3 4 5 6 7 8 9 10 11 12
$lightweight_fh = $q->upload('field_name'); # undef may be returned if it's not a valid file handle if (defined $lightweight_fh) { # Upgrade the handle to one compatible with IO::Handle: my $io_handle = $lightweight_fh->handle; open (OUTFILE,'>>','/usr/local/web/users/feedback'); while ($bytesread = $io_handle->read($buffer,1024)) { print OUTFILE $buffer; } }
../var/www/meine.domain.test/.htaccess