Esteemed monks,

For quite some time I have had a variety of scripts doing file uploads from a variety of browsers. Today I ran into a problem when using AOL Explorer. This runmode is taken form a CGI::Application application, and I find that when I look at the value of  $filename at the end of the method, it has the FULL original file name including the Windoze path.

sub landingpage_template_upload_graphic { my $self = shift; my $page = $self->_gen_pgwrapper(); my $q = $self->query; $dir = "/home/finc/www/content/sts/images/campaigns/"; my $filename; my $filehandle; if ( $filename = $q->param('image') ) { if ( $filename =~ /^([\w-]+\.(jpg|gif|png|jpeg))$/ ) { $filehandle = $filename; $filename = $1; open( OP, ">$dir/$filename" ) or die "$!"; chmod 0777, "$dir/$filename"; binmode OP; my $buffer; my $bytesread; while ( $bytesread = read( $filehandle, $buffer, 1024 ) ) { print OP $buffer; } close $filehandle; } } #} $page->param( 'warning' => Dumper($q) . "\nName: $filename\nDirector +y: $dir\n" ); return $page->output(); }
Obviously I have to modify the REGEX I am using to clean up the filename, but how do I come up with one that will work for all browsers?

jdtoronto


In reply to CGI upload script problem with Explorer. by jdtoronto

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.