through CGI.pm on a CGI::App, catching the result on the server with<form action='/Post' method='post' name='FileUpload' enctype='multipar +t/form-data'> <input type='file' name='filename'>
and the Dumper above gives me some insight into the problem on files which contain quotes in their name. For example, when I upload a file like Some file with "quotes".txt I get this Dump back from the server:if($ENV{'REQUEST_METHOD'} eq "POST"){ my $form = {}; $form->{filename} = $q->param('filename'); my $tempfile = $q->tmpFileName($form->{filename}); return Dumper($form,$tempfile); ...
$VAR1 = {
'filename' => bless( \*{'Fh::fh00001Some file with \\'}, 'Fh' ),
};
$VAR2 = \'/var/tmp/CGItemp5543'
The tmp file ends up on the server okay, but the incomplete filename screws up my script. So, anything that springs to mind, some stupid escaping I am not caring about? "If you want the entered file name for the file, you can just call param():
$filename = $q->param('field_name');
No, it obviously doesn't.
Different browsers will return slightly different things for the name. Some browsers return the filename only. Others return the full path to the file, using the path conventions of the user's machine. Regardless, the name returned is always the name of the file on the user's machine, and is unrelated to the name of the temporary file that CGI.pm creates during upload spooling (see below). When a file is uploaded the browser usually sends along some information along with it in the format of headers. The information usually includes the MIME content type. To retrieve this information, call uploadInfo(). It returns a reference to a hash containing all the document headers."The latter, I then implemented in my script:
Dumping that returns:my $upload_meta = $q->uploadInfo($form->{filename});
$VAR1 = { 'filename' => bless( \*{'Fh::fh00001Some file with \\'}, 'Fh' ) };
$VAR2 = { 'Content-Type' => 'text/plain', 'Content-Disposition' => 'form-data; name="file"; filename="Some file with \\"quotes\\".txt"' };
There it is, the full filename in all its glory. But: Am I really supposed to parse the Content-Disposition header? I am not even sure if all browser/OS combinations reliably set this header...
In reply to Unable to get filename with quotes after upload? by isync
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |