hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : Perl uploading
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

Perl uploading

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 10-12-2003, 09:35 AM
LinuxNerd LinuxNerd is offline
Junior Guru
 
Join Date: Dec 2002
Posts: 186

Perl uploading


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.

__________________
I don't post to spam my sig. I post for the love

Reply With Quote


Sponsored Links
  #2  
Old 10-12-2003, 11:41 AM
Chas Chas is offline
WHT Addict
 
Join Date: Apr 2001
Location: California
Posts: 131
Hey gamesxposed,

Your problem, answer really, is more in line with mod_rewrite, not Perl. Do a serach in this forum or the technical forum for mod_rewrite and I'm sure you'll find more than a few examples to prevent linking from your site.

~Charlie
:wq

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
cPanel & WHM Software 11.36 Reaches Stable Tier Status Web Hosting News 2013-04-09 11:44:33
cPanel Security Updates Address Perl Module Vulnerabilities Web Hosting News 2012-12-06 12:55:54
Softaculous Launches AMPPS Installer Version 1.5 Web Hosting News 2012-01-26 16:52:40
Web Host Liquid Web Donates $10,000 to The Perl Foundation Web Hosting News 2011-09-23 18:45:40
Web Host A2 Hosting Launches QuickInstaller Tool for VPS Plans Web Hosting News 2011-08-19 20:00:53


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?