Guest_imported
New member
- Jan 1, 1970
- 0
I'm having a heck of a time trying to write a website admin tool, every thing was going well till i tried to add a file uploader!!!
my program works fine in the sense it uploads the correct file, to the correct place with the correct name, even the file size is the same as the original...HOWEVER....
when you try to open the uploaded file it is corrupt.
any help would be great,
here's my code....
#!/usr/bin/perl
use CGI;
$cgi = new CGI;
$ft = $cgi->param('ft');
$file = $cgi->param('fl');
$domain = "$err_url = "$domain/err.htm";
$id = $cgi->param('userid');
$pw = $cgi->param('password');
$fa = $cgi->param('FA');
$type = $cgi->uploadInfo($file)->{'Content-Type'};
$desc = "File Upload";
$cmd = $cgi->param('cmd');
$len = length($file);
$pos = $len-3;
$ext = substr($file,$pos,3);
if($file eq ""{$mess="[Upload failed!] - No file selected.";&error;}
else {
if($ft eq "rm"{$dir = "./tmp/mp3";
if($ext ne ".rm"{$mess="[Upload failed!] - Invalid file type selected.";&error;};
};
if($ft eq "mp3"{$dir = "./tmp/mp3";
if($ext ne "mp3"{$mess="[Upload failed!] - Invalid file type selected.";&error;};
};
if($ft eq "jpg"{$dir = "./tmp/images";
if($ext ne "jpg"{$mess="[Upload failed!] - Invalid file type selected.";&error;};
};
if($ft eq "gif"{$dir = "./tmp/images";
if($ext ne "gif"{$mess="[Upload failed!] - Invalid file type selected.";
}
if($ft eq ""{
if($file ne ""{$mess="[Upload failed!] - No file type selected.";&error;
};
}
if($mess eq ""{$mess="[Upload Complete!]<br><br><font color=black><b>$file";}
$file=~m/^.*(\\|\/)(.*)/; # strip the remote path and keep the filename
$name = $2;
open(LOCAL, ">$dir/$name" or die $!;
binmode(LOCAL);
while(<$file>) {
print LOCAL $_;
}
&uploaded;
#### error & uploaded subs ---->>>>
Ok although i said the file was going to the right place I also have another question... is it possible to use PERL/CGI to FTP the uploaded file to another one of our servers giving the perl code the correct username & password details.???
cheers,
craig.
my program works fine in the sense it uploads the correct file, to the correct place with the correct name, even the file size is the same as the original...HOWEVER....
when you try to open the uploaded file it is corrupt.
any help would be great,
here's my code....
#!/usr/bin/perl
use CGI;
$cgi = new CGI;
$ft = $cgi->param('ft');
$file = $cgi->param('fl');
$domain = "$err_url = "$domain/err.htm";
$id = $cgi->param('userid');
$pw = $cgi->param('password');
$fa = $cgi->param('FA');
$type = $cgi->uploadInfo($file)->{'Content-Type'};
$desc = "File Upload";
$cmd = $cgi->param('cmd');
$len = length($file);
$pos = $len-3;
$ext = substr($file,$pos,3);
if($file eq ""{$mess="[Upload failed!] - No file selected.";&error;}
else {
if($ft eq "rm"{$dir = "./tmp/mp3";
if($ext ne ".rm"{$mess="[Upload failed!] - Invalid file type selected.";&error;};
};
if($ft eq "mp3"{$dir = "./tmp/mp3";
if($ext ne "mp3"{$mess="[Upload failed!] - Invalid file type selected.";&error;};
};
if($ft eq "jpg"{$dir = "./tmp/images";
if($ext ne "jpg"{$mess="[Upload failed!] - Invalid file type selected.";&error;};
};
if($ft eq "gif"{$dir = "./tmp/images";
if($ext ne "gif"{$mess="[Upload failed!] - Invalid file type selected.";
}
if($ft eq ""{
if($file ne ""{$mess="[Upload failed!] - No file type selected.";&error;
};
}
if($mess eq ""{$mess="[Upload Complete!]<br><br><font color=black><b>$file";}
$file=~m/^.*(\\|\/)(.*)/; # strip the remote path and keep the filename
$name = $2;
open(LOCAL, ">$dir/$name" or die $!;
binmode(LOCAL);
while(<$file>) {
print LOCAL $_;
}
&uploaded;
#### error & uploaded subs ---->>>>
Ok although i said the file was going to the right place I also have another question... is it possible to use PERL/CGI to FTP the uploaded file to another one of our servers giving the perl code the correct username & password details.???
cheers,
craig.