Home: Perl Programming Help: Intermediate:
A little CGI upload script help.

New User

Jun 22, 2011, 7:32 AM

Views: 1650
A little CGI upload script help.

Hi i literally just jumped into perl and i have this problem. I wrote a script:

#!/usr/bin/perl -w 

use strict;

use CGI;

use CGI::Carp qw ( fatalsToBrowser );

use File::Basename;

my $safe_filename_characters = "a-zA-Z0-9_.-";

my $upload_dir = '/usr/lib/cgi-bin/SNP';

my $query = new CGI;

my $filename = $query->param('input_file');

my ( $name, $path, $extension ) = fileparse ( $filename, '\..*' );

$filename = $name . $extension;

$filename =~ tr/ /_/; $filename =~ s/[^$safe_filename_characters]//g;

if ( $filename =~ /^([$safe_filename_characters]+)$/ ) { $filename = $1; } else { die "Filename contains invalid characters";


$filename=~m/^.*(\\|\/)(.*)/; # strip the remote path and keep the filename

my $name = $2;

#my $upload_filehandle=$query->upload('input_file');

open(LOCAL, ">$upload_dir/$name") or die $!;

while(<$name>) {

print LOCAL $_;}

# open ( UPLOADFILE, ">/SNP/$name" ) or die "$!";

# binmode UPLOADFILE; while ( <$upload_filehandle> ) { print UPLOADFILE;

# }


print <<END_HTML;





<body> <p>Thanks for uploading</p> <p><a href src="/SNP/$filename"/>FILE</a></body> </html>


That is supposed to handle a file from a form and upload it to the server. I keep getting this error:

Software error: 

Is a directory at /usr/lib/cgi-bin/SNIP.cgi line 21.

For help, please send mail to the webmaster (webmaster@localhost), giving this error message and the time and date of the error.

Whats going on here? Searched on other forums. Havent found anything...