Hi. I have a script that takes a filename, checks to make it exists, and renames it to another name, if that name ends in the proper extension. Could someone please help me?
#!/usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);
if ($ENV{'REQUEST_METHOD'} eq 'GET') {
@pairs = split(/&/, $ENV{'QUERY_STRING'});
} elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
if ($ENV{'QUERY_STRING'}) {
@getpairs =split(/&/, $ENV{'QUERY_STRING'});
push(@pairs,@getpairs);
}
} else {
print "Content-type: text/html\n\n";
print "<P>Use Post or Get";
}
foreach $pair (@pairs) {
($key, $value) = split (/=/, $pair);
$key =~ tr/+/ /;
$key =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~s/<!--(.|\n)*-->//g;
if ($formdata{$key}) {
$formdata{$key} .= ", $value";
} else {
$formdata{$key} = $value;
}
}
$method=$formdata{'method'};
$nm=$formdata{'filename'};
$user=$formdata{'user'};
if($method eq "rename")
{
$toName=$formdata{"rename-to"};
$allowed=0;
open (BUFFERING, ">>acceptable.txt");
@buffy=<BUFFERING>;
close BUFFERING;
foreach $type (@buffy)
{
if($toName =~ /\w{1,}\.$type/g)
{
$allowed=1;
}
}
if(-e "../albums/$user/$nm" && $allowed==1)
{
rename ("../albums/$user/$nm", "../albums/$user/$toName");
}
}
print "Location:album.cgi?id=$formdata{'user'}\n\n";
#!/usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);
if ($ENV{'REQUEST_METHOD'} eq 'GET') {
@pairs = split(/&/, $ENV{'QUERY_STRING'});
} elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
if ($ENV{'QUERY_STRING'}) {
@getpairs =split(/&/, $ENV{'QUERY_STRING'});
push(@pairs,@getpairs);
}
} else {
print "Content-type: text/html\n\n";
print "<P>Use Post or Get";
}
foreach $pair (@pairs) {
($key, $value) = split (/=/, $pair);
$key =~ tr/+/ /;
$key =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~s/<!--(.|\n)*-->//g;
if ($formdata{$key}) {
$formdata{$key} .= ", $value";
} else {
$formdata{$key} = $value;
}
}
$method=$formdata{'method'};
$nm=$formdata{'filename'};
$user=$formdata{'user'};
if($method eq "rename")
{
$toName=$formdata{"rename-to"};
$allowed=0;
open (BUFFERING, ">>acceptable.txt");
@buffy=<BUFFERING>;
close BUFFERING;
foreach $type (@buffy)
{
if($toName =~ /\w{1,}\.$type/g)
{
$allowed=1;
}
}
if(-e "../albums/$user/$nm" && $allowed==1)
{
rename ("../albums/$user/$nm", "../albums/$user/$toName");
}
}
print "Location:album.cgi?id=$formdata{'user'}\n\n";