我一直在嘗試基於Perl的Mojolicious web框架。我試圖開發一個完整的應用程序,而不是Lite。我面臨的問題是我試圖上傳文件到服務器,但下面的代碼不起作用。如何使用Mojolicious上傳文件?
請指導我它有什麼問題。另外,如果文件上傳,那麼它是在應用程序的公用文件夾或其他地方。
在此先感謝。
sub posted {
my $self = shift;
my $logger = $self->app->log;
my $filetype = $self->req->param('filetype');
my $fileuploaded = $self->req->upload('upload');
$logger->debug("filetype: $filetype");
$logger->debug("upload: $fileuploaded");
return $self->render(message => 'File is not available.')
unless ($fileuploaded);
return $self->render(message => 'File is too big.', status => 200)
if $self->req->is_limit_exceeded;
# Render template "example/posted.html.ep" with message
$self->render(message => 'Stuff Uploaded in this website.');
}
我看到Mojolicious ::精簡版文檔調用'$自我> req->上傳()'是包裹在一個'if()'中,這意味着在假定有一個上傳之前它的返回值被檢查。這樣做相當於檢查開放的回報值,我想。 – DavidO 2012-04-14 15:10:07