Well here it is, the first ever perl script, and proberly my last.
After seeing perl, i think i will stick with PHP, the reason why i made this in perl was because i didnt like the way PHP uploaded things, anyways, i have completed this uploader, and i was wondering how i could make it so a certain domain (forum) cannot link to any images uploaded on my server, i know there is a forum that is leeching off me, so i want to disable all hotlinks, anyways heres the code, a bit of help would be great!
Code:
#!/usr/bin/perl
use CGI;
my $query=new CGI;
# path to uploads, leave slash at end, length of upload files
my $path = "images2/",my $length="1048576";
my @types=("jpg","jpeg","gif");
print $query->header;
print "<html>\n";
print "<head>\n";
print "<title>Gamesxposed Uploader</title>\n";
print "<link href=\"upload.css\" rel=\"stylesheet\" type=\"text/css\" />\n";
print "</head>\n";
print "<body>\n";
print "<table width=\"100%\" cellpadding=\"2\" cellspacing=\"1\" border=\"0\" class=\"forumline\">\n";
print "<tr><th height=\"25\" nowrap=\"nowrap\" class=\"\">Image Upload</th></tr>\n";
print "<tr><td class=\"row1\">\n";
if ($submit = $query->param('submit')) {
if ($ENV{'CONTENT_LENGTH'} > $length) { print "File too big ($length bytes is max)!\n"; exit; }
my $filename=$query->param('userdata');
$filename=~s/.*[\/\\](.*)/$1/;
my @sp=split(/\./,$filename);
my $ext=pop @sp;
if (!$ext) { print "Improperly labeled file!\n"; exit; }
$ext=lc($ext);my $b;
for(my $i=0;$i<@types;$i++) {
if ($types[$i] eq $ext) { $b=1; }
}
if (!$b) { print "Unknown file type, please upload "."@types"."\n"; exit; }
my $udata = $query->upload('userdata');
my $rand=time;
my $fpath=$path.join('',"@sp").".$rand.$ext";
if (stat($fpath)) { print "Cannot write, file already exists!\n"; exit; }
if (!open(FD,">$fpath")) {
print "Cannot open write file: $!\n"; exit;
}
while(<$udata>) {
print FD $_;
}
close FD;
print "<br /><div style=\"text-align: center;\"><div class=\"code\">";
print "Your Image supplied by GamesXposed.net :<br />";
print "<img src=\"$fpath\" /><br />";
print "The url to your image is:<br /><a href=\"$fpath\">http://www.blizzardhacks.net/upload/$fpath</a>\n";
print "</div></div>";
print "<br /><br /><i>Upload Another:</i>";
}
print '<FORM ACTION="'.$ENV{'SCRIPT_NAME'}.'" NAME="upload" METHOD="post" ENCTYPE="multipart/form-data">
<INPUT TYPE="hidden" NAME="MAX_FILE_SIZE" VALUE="'.$length.'">
<INPUT TYPE="file" name="userdata" class=input>
<INPUT TYPE="submit" name="submit" value="Upload" class=input>
</FORM><span class="genmed">Please be patient while it uploads..</span>';
print "</td>";
print "</tr>";
print "</table";
print "</body>";
print "</html>";
Demo:
http://gamesxposed.com/upload/
Thanks in advance.