0

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'; }

1 Answers1

0

Your uploadFile method in Site.pm should finish with a line something like:

$c->res->redirect($c->uri_for('/your-upload-page-location'));

... so that after calling the upload processing action, the browser is directed back to the original page to repeat the process if required. At the moment the uploadFile action has no instruction on what to do next.

'your-upload-page-location' is obviously the action that rendered the form in the first place.

Hope that helps.

RET
  • 9,100
  • 1
  • 28
  • 33
  • You're welcome. You might like to consider upvoting the answer and/or ticking it to mark it as the solution. – RET Jan 15 '13 at 12:21