in html baust du ein:
<form ENCTYPE="multipart/form-data" method="post" action="klfjsd"><input type=file name=datei>
in cgi baust du ein:
&parse_form;
&process_upload('./','datei');
sub parse_form
{
$query_of_CGI = new CGI;
foreach $key (sort {$a <=> $b} $query_of_CGI->param())
{
$value = $query_of_CGI->param($key);
if ($key ne "home-bild" && $key ne "archiv-bild")
{
$value = &newline_to_tags($value);
}
$Formular{$key} = $value;
}
}
#lädt eine datei auf den server
sub process_upload
#parameter: pfad zum ablegen (mit trailing /), formularfeldname = filehandle
{
local($path,$fieldname)=@_;
local($Bytes,$Buffer,$filehandle);
$filehandle = $query_of_CGI->param($fieldname);
#die pfadangaben rauslöschen
$saveas = $filehandle;
$saveas =~ s/.\*\\([a-zA-Z0-9\_.-]\*)/$1/sgi;
$saveas =~ s/.\*\/([a-zA-Z0-9\_.-]\*)/$1/sgi;
if(!$filehandle)
{
print "debug: übersprungen";
return;
}
if (-e ("$path"."$saveas"))
{
die "file existiert! (".$path.$saveas.")";
}
if (open(OUTFILE,">$path"."$saveas"))
{
while ($Bytes = read($filehandle,$Buffer,1024))
{
$BytesRead += $Bytes;
print OUTFILE $Buffer;
}
close OUTFILE; close(OUTFILE);
}
else
{
die "kann $path"."$saveas nicht schreibend öffnen!";
}
chmod (0664,"$path"."$saveas");
}
gruesse gerhard