Any help very much appreciated. Thanks very much.
Expand|Select|Wrap|Line Numbers
- #!/usr/bin/perl -w
- use CGI;
- my $cgi = new CGI;
- my $file = $cgi->param('file');
- my $fileName = $cgi->param('file');
- @types = ("jpg", "gif");
- my ( $type_ok, $file_contents, $buffer);
- @sitess=("site1", "site2");
- foreach $sitess (@sitess){
- print "Content-type: text/html\n\n";
- # get the extension
- my @file_type = split(/\./, $fileName);
- # we can assume everything after the last . found is the extension
- my $file_type = $file_type[$#file_type];
- # get the file name, this removes everything up to and including the
- # last slash found ( be it a forward or back slash )
- $fileName =~ s/^.*(\\|\/)//;
- # remove all spaces from new instance of filename var
- $fileName =~ s/\s+//ig;
- # check for any any non alpha numeric characters in filename (allow dots and dahses)
- $fileName =~ s/\./PsJsDoT/g;
- $fileName =~ s/\-/PsJsDaSh/g;
- if($fileName =~ /\W/){
- $fileName =~ s/\W/n/ig; # replace any bad chars with the letter "n"
- }
- $fileName =~ s/PsJsDoT/\./g;
- $fileName =~ s/PsJsDaSh/\-/g;
- # if $file_type matches one of the types specified, make the $type_ok var true
- for($b = 0; $b < @types; $b++){
- if($file_type =~ /^$types[$b]$/){
- $type_ok++;
- }
- if($types[$b] eq "ALL"){
- $type_ok++; # if ALL keyword is found, increment $type_ok var.
- }
- }
- $overwrite=1;
- # if ok, check if overwrite is allowed
- if($type_ok){
- open ( UPLOADFILE, ">/$sitess/path/$fileName" ) or die "$!";
- binmode UPLOADFILE;
- #$VAR{err} .= $!;
- while (read($file, $buffer, 1024))
- {
- print UPLOADFILE $buffer;
- }
- close UPLOADFILE;
- print "<font color=\"red\">hi</font></p>";
- print "<p>$fileName :: <a href=\"http://www.$sitess.com/$fileName\"><img src=\"http://www.$sitess.com/$fileName\"></a></p>";
- }
- }
- 1;