I have written an upload.tmpl with <input type="file" name="uploadfile">. And link this tmpl to upload.pl. However, when the cgi->param("uploadfile") is passed in the upload.pl, it doesn't seems to work the way it is supposed to. I think it's only passing as string instead of a filehandle. I tried it without the HTML::Template and it works fine. But when I used the template, it just doesn't work.
The script for upload.pl is as follow:
my $cgi = CGI->new();
my $template = HTML::Template->new(filename => "upload.tmpl", path => "/var/www/html/");
my $filename = $cgi->param("uploadfile");
$filename =~ s/.*[\\/\\](.*)/$1/;
my @text = <$filename>;
my $text = join(",", @text);
$template->param(text => $text);
The upload.tmpl is as follows:
<form method="post" action="/cgi-bin/upload.pl">
<input type="file" name "uploadfile" size="40" />
<input type="submit" value="upload" />
<td><!-- tmpl_var="text" --></td>
Appreciate the help!! Thanks.
You must set the form enctype to "multipart/form-data" for file uploads to work:
<form method="post" action="/cgi-bin/upload.pl" enctype="multipart/form-data">
I really wish browsers would produce a warning about this, it's bitten me a few times too.
Thanks a lot Sam. I did put it in my original file. I must have missed it when I put it here. I went back to check again, it was a typo mistake that I've made. Instead of "enctype", I've typed "enctpye". Sorry for the false alarm. Thanks again.
One thing I don't get is why it worked when he just used it as an HTML webpage. The form enctype seems to have become an issue after he made it a template.
Log in to post a comment.