Wenn der Client (der Browser) nicht den vollstaendigen Pfad sendet, kann man ihn auch nicht im CGI-Script auslesen.Folgendes Script sendet eine HTTP-POST-Anfrage, die die Datei '/tmp/tempfile' hochlaedt und fuer das 'filename'-Attribut den vollstaendigen Pfad verwendet.
none@ruby:~$ vi http_post_fileupload.pl
#!/usr/bin/perl use strict;
use warnings;
use LWP::UserAgent;
my $url = 'http://example.org/fileupload/';
my $ua = LWP::UserAgent->new;
my $resp = $ua->post($url, Content_Type => 'form-data',
Content => [
myfile => ["/tmp/tempfile",
"/tmp/tempfile"
]
]);
unless($resp->is_success) {
die $resp->status_line, "\n";
}
print $resp->content();
Wuerde in den anonymen Array fuer 'myfile' nur ein Element mit dem Pfad stehen, dann wuerde auch hier fuer das 'filename'-Attribut der Teil des Pfads bis auf den Dateinamen entfernt werden.Es ist also Sache der Client-Software den vollstaendigen Pfad mit zu uebermitteln und nicht Aufgabe des CGI-Scripts.
Hier der entsprechende Abschnitt aus dem RFC 2388 - Returning Values from Forms: multipart/form-data
4.4 Other attributes Forms may request file inputs from the user; the form software may
include the file name and other file attributes, as specified in [RFC
2184].
The original local file name may be supplied as well, either as a
"filename" parameter either of the "content-disposition: form-data"
header or, in the case of multiple files, in a "content-disposition:
file" header of the subpart. The sending application MAY supply a
file name; if the file name of the sender's operating system is not
in US-ASCII, the file name might be approximated, or encoded using
the method of RFC 2231.
This is a convenience for those cases where the files supplied by the
form might contain references to each other, e.g., a TeX file and its
.sty auxiliary style description.
Datum: 21.06.2007-15:31
