Hi there,

I am uploading files to a webserver with
<form action='/Post' method='post' name='FileUpload' enctype='multipar +t/form-data'> <input type='file' name='filename'>
through CGI.pm on a CGI::App, catching the result on the server with
if($ENV{'REQUEST_METHOD'} eq "POST"){ my $form = {}; $form->{filename} = $q->param('filename'); my $tempfile = $q->tmpFileName($form->{filename}); return Dumper($form,$tempfile); ...
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:
$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?
Underlying filesystem is Reiser, which allows quotes, when escaped with \ on creation.

Update:
Note: adapted the title, as the FH, although it is truncated name-wise, seems to work.

I am uploading from Linux+Firefox to a Debian server, btw.
After reading the CGI docs on cpan closely again:
"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:
my $upload_meta = $q->uploadInfo($form->{filename});
Dumping that returns:
$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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.