Please do not let random uploaders from the outside give files names on your system.

Ideally, you save the uploaded data to a file using a random name (or simply a number) and store the uploaded filename in a database together with the local name on your filesystem.

The actual filename of your temporary upload file is available through the ->upload() and ->tmpFileName methods. But the CGI documentation shows their usage different from what you do:

my $filehandle = $q->upload( 'uploaded_file' ); my $tmpfilename = $q->tmpFileName( $filehandle );

Maybe if you adapt your code to use the functions as in the documentation it will work better?

Personally, I would use File::Copy to copy data from the /tmp directory instead of hoping that rename will work.

Maybe you will also find Text::CleanFragment helpful, which converts arbitrary text to ASCII without spaces, which is mostly harmless to use in filenames.


In reply to Re: File upload with empty temp handle value by Corion
in thread File upload with empty temp handle value by Anonymous Monk

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.