我已经写了“fileUpload.tt”和“Site.pm”来上传文件(粘贴在下面)。它将文件上传到“/tmp”目录,但问题是,在上传文件后,它会进入带有 URL (XXX/MySite/uploadFile) 的空白屏幕。我希望它在同一个屏幕上,并且应该允许我上传另一个文件。我尝试在中给出“onsubmit="return false;",然后它甚至没有上传文件。请让我知道如何做到这一点..
文件上传.tt:
<form action="/MySite/uploadFile" method="post" enctype="multipart/form-data">
<input type="hidden" name="form_submit" value="yes">
<input type="file" name="my_file">
<input type="submit" value="Send">
</form>
网站.pm:
sub uploadFile :Local :Args(0){
my ( $self, $c ) = @_;
if ( $c->request->parameters->{form_submit} eq 'yes' ) {
if ( my $upload = $c->request->upload('my_file') ) {
my $basename = $upload->basename;
my $target = "/tmp/$basename";
$upload->copy_to($target) )
}
}
$c->stash->{'template'} = 'fileUpload.tt'; }