我如何用html创建按钮以在perl中符号链接文件?

问题描述 投票:0回答:1

我在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>

所以我想要的是当我单击符号链接按钮时会发生对不起,我的英语

perl symlink
1个回答
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>
© www.soinside.com 2019 - 2024. All rights reserved.