I've written 'fileUpload.tt' and 'Site.pm' to upload file (pasted below). Its uploading file to '/tmp' directory but the problem is that, after uploading the file, its going to blank screen with URL (XXX/MySite/uploadFile). I want it to be in the same screen and should allow me to upload another file. I tried giving "onsubmit="return false;" in the , then it was not even uploading the file. Please let me know how to do this..
fileUpload.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>
Site.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'; }