willy96: CGI/Perl Upload Script

Beitrag lesen

Wollte das ganze jetzt so (mit system copy anweisung) machen allerdings gibt er mir zwar aus dass die Datei so und so heisst etc aber kopiert sie nicht in das erwünschte Verzeichnis.

GNU nano 2.2.6                     Datei: upload.pl

#!/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/$c';
my $new = '/Fileserver/Frederik/$c';

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 "</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->end_form;
}