nixp.ru v3.0

20 апреля 2024,
суббота,
04:30:54 MSK

Hekt0r написал 12 сентября 2004 года в 08:06 (1097 просмотров) Ведет себя как мужчина; открыл 1 тему в форуме.

А вы бы не могли поделиться исходником скрипта upload.pl или рассказать, как его написать?

Genie

а можно встречный вопрос: чем google://script upload file perl не устраивает?

Дмитрий Шурупов

Тему это только сейчас заметил, но, как понимаю, вопрос уже решили в IRC…

MaGIc2laNTern

И все же, Шуруп, может выложишь сырки?

А то мне тоже очень любопытно посмотреть.

Тем более что я собераюсь в ближайшем будущем изучать Perl.

myst

Так ты вначале изучи…

Дмитрий Шурупов

Ну, основной кусок вот:

# file size limit in Kbytes
my $limit=512;
# dir with temp uploaded files
my $udir="";
# users' upload file
my $ufile="";
use CGI;
use CGI::Cookie;
my %cookies = fetch CGI::Cookie;
# проверяем, зарегистрированный ли это пользователь, который вошел в форум
# оставляем в $nixpl его логин (для гостя -- "Guest")
print "Content-type: text/html\n\n";
print qq~<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html>
<body>

</head>

Page for uploading files to the «Trash»</a> at nixp.ru/forum/</a>.

File size limit: \~$limit Kb.

\n~;

if ($nixpl eq «Guest»){ print qq~Only registered</a> users are allowed to upload anything.

\n~; } else {

my $in=new CGI; my $action=$in->param(’a'); $action=«def» if (!$action || $action ne «up»);

if ($action eq «def»){

print qq~
<form method=«post» action=«upload.pl» name=«main» enctype=«multipart/form-data» id=«main»>

<input type=«hidden» name=«a» value=«up»>

Choose file: <input type=«file» name=«tfile»>

<input type=«submit» value=«Upload»>

</form>

~;

} elsif ($action eq «up»){

if ($ENV{’CONTENT_LENGTH’}<$limit*1024){

my $cstr; my $alright=1; my $nowtime=time;

if (open(UPF,«$ufile»)){

while($cstr=){ chomp($cstr); $cstr=~/:=:/; if ($' eq $nixpl && $nowtime-$`<180){ $alright=0; } }

close(UPF);

if (!$alright){ print «You have uploaded something just few moments ago. So, now you have to wait.\n»; } else {

my $tfile=$in->param(’tfile’); $tfile=$1 if ($tfile=~/[\\\/]([^\\\/]+)$/); my $ofile=«$udir/$nowtime.$nixpl.$tfile»;

if (open(WF,«>$ofile»)){

sleep 1 unless(flock(WF,2));

my $ufh=$in->upload(’tfile’); binmode(WF);

while (<$ufh>){ print WF; }

close(WF);

if (open(UPF,«$ufile»)){

chomp(my @ufilec=); close(UPF);

if (open(UPF,«>$ufile»)){

sleep 1 unless(flock(UPF,2));

foreach $cstr(@ufilec){ $cstr=~/:=:/; if ($' ne $nixpl){ print UPF «$cstr\n»; } }

print UPF «$nowtime:=:$nixpl\n»; close(UPF);

print «FIle $tfile has been successfully uploaded. Wait for moderator checking.\n»;

sub use_sendmail{

if (open(MAIL,"|/usr/sbin/sendmail $_[0]»)){

print MAIL <<end_of_MAIL;

X-Mailer: sendmail

From: root\@nixp.ru

X-ident-From: unknown

Content-Type: text/plain; charset=CP1251

Subject: $_[1]

To: $_[0]\n

$_[2]\n

end_of_MAIL

close(MAIL);

} else { print «sendmail error»; }

}

&use_sendmail(«„,“Trash — new file«,»$nixpl uploaded new file to the 'Trash’. Moderate it here: »);

} else { print «DB error.\n»; }

} else { print «DB error.\n»; }

} else { print «Can’t create file.\n»; }

}

} else { print «DB error.\n»; }

} else { print «File you want to upload is too big.\n»; }

}

}

print qq~

upload index</a>

\n\n</body>\n</html>\n~;
</form>
</body>
</html>

Последние комментарии

ecobeingecobeing.ru
Экология и вегетарианство на благо всем живым существам Планеты.