我在perl中遇到问题我正在使用脚本实际上是symlink工具,所以我尝试创建一个按钮 名为symlink的符号链接到名为/ etc / passwd的文件 所以我怎么称呼,但这些在一起
$target="/etc/passwd";
$distension ="1.txt";
$symlink = symlink($target,$distension);
if($symlink == 1) {print " distension symlink created successfully";}
else {print "cannot symlink File $distension Already Exists ";}
<button value="" name="symlink" type="button"
onclick="alert('symlink created successfully ^_^')">symlink</button>
所以我想要的是当我单击将发生的符号链接按钮时 对不起我的英语
答案 0 :(得分:2)
Perl程序需要在Web服务器中运行或作为Web服务器运行。示例:
app.psgi
#!/usr/bin/env plackup
use strict;
use warnings;
use Plack::Request qw();
use HTTP::Status qw(
HTTP_OK HTTP_METHOD_NOT_ALLOWED HTTP_INTERNAL_SERVER_ERROR
);
my $app = sub {
my ($env) = @_;
my $req = Plack::Request->new($env);
if ('POST' eq $req->method) {
my $target = '/etc/passwd';
my $distension = '1.txt';
if (symlink $target, $distension) {
return $req->new_response(
HTTP_OK, ['Content-Type' => 'text/plain'], [
'distension symlink created successfully'
]
)->finalize;
print ;
} else {
return $req->new_response(
HTTP_INTERNAL_SERVER_ERROR, ['Content-Type' => 'text/plain'], [
"could not symlink <$target> to <$distension>: $!"
]
)->finalize;
}
} else {
return $req->new_response(HTTP_METHOD_NOT_ALLOWED)->finalize;
}
};
HTML表单需要引起对Web服务器的POST请求。
<form method="POST" action="http://localhost:5000">
<input type="submit" value="create symlink">
</form>