#!I:\Interwoven\TeamSite\iw-perl\bin\iwperl -wT use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser set_message); set_message("It's not a bug, it's a feature!"); use Fcntl qw(:flock); use strict; print header, start_html(-title=>'Upload file to server'), =>h3('Upload local file from PC to teamsite'), start_multipart_form, 'Click on the browse button to choose a filename: ', filefield( -name => 'upfile', -size => 50, -maxlength => 80), hr, submit(-name=>'Upload File'), hr, end_form; my $file = param("upfile"); my $upload_dir = "Y:\\Test\\user\\videos\\"; my $fh; unless ( $file ) { print "Nothing uploaded?<p>\n"; } else { my $outfile = "$upload_dir".""; my ($safe_file_name) = $outfile =~ /([-\@:\/\\\w.]+)$/; if ($file =~ /swf/ || $file =~ /high/ || $file =~ /low/) { $outfile .= $file; #if (-e $outfile) { # error_msg("File already exist in destination folder"); #} } else { error_msg("Only '.swf' files and files with 'high' or 'low' in +the name will be uploaded."); } $safe_file_name = $1; if (!$safe_file_name) { die qq{Disallowed characters in file $safe_file_name\n}; } my $file_len = 0; open (my $fh, '>', $safe_file_name) or error_msg("Can't open $safe_file_name for writing: $!"); flock( $fh, LOCK_EX ); while ( read( $file, my $i, 1024 ) ) { print $fh $i; $file_len = $file_len + 1024; if ( $file_len > 1024000 ) { close($fh); error_msg("Error - file is too large. Save aborted.<p>"); } } close($fh); print "File: $file<br>\n"; print "Size: ", $file_len / 1024, "KB<br>\n"; print "Uploaded to: $safe_file_name<p>\n"; } print end_html; sub error_msg { my ($msg) = @_; print "<h2>Error</h2>\n"; print "$msg<p>\n"; exit; }

I'm getting "Disallowed characters in file"

...

I'm trying different methods with taint to find answer

so far no luck. I get error above or "Insecure dependency in open while running with -T switch" error


In reply to Upload file through perl-cgi not working by becool321

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.