jdtoronto has asked for the wisdom of the Perl Monks concerning the following question:
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.
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?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(); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: CGI upload script problem with Explorer.
by philcrow (Priest) on Jul 25, 2006 at 16:02 UTC | |
by Joost (Canon) on Jul 25, 2006 at 16:09 UTC | |
|
Re: CGI upload script problem with Explorer.
by eric256 (Parson) on Jul 25, 2006 at 17:42 UTC | |
|
Re: CGI upload script problem with Explorer.
by Ieronim (Friar) on Jul 25, 2006 at 17:53 UTC | |
by jdtoronto (Prior) on Jul 25, 2006 at 20:40 UTC | |
by Ieronim (Friar) on Jul 25, 2006 at 22:27 UTC | |
|
Re: CGI upload script problem with Explorer.
by jfluhmann (Scribe) on Jul 26, 2006 at 14:05 UTC |