From 20e3f3c8cd6711f9e2880f0b57b28389d057f5d5 Mon Sep 17 00:00:00 2001 From: Stig Lindqvist Date: Fri, 11 May 2012 11:39:24 +1200 Subject: [PATCH] BUGFIX: The EditableFileField crashed when user uploads a not allowed filetype --- code/model/UserDefinedForm.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/code/model/UserDefinedForm.php b/code/model/UserDefinedForm.php index ee1f4fd..5e65778 100755 --- a/code/model/UserDefinedForm.php +++ b/code/model/UserDefinedForm.php @@ -660,7 +660,7 @@ JS } if(Session::get("FormInfo.{$form->FormName()}.errors")){ - Director::redirectBack(); + Controller::curr()->redirectBack(); return; } @@ -701,8 +701,14 @@ JS $upload = new Upload(); $file = new File(); $file->ShowInSearch = 0; - - $upload->loadIntoFile($_FILES[$field->Name], $file); + try { + $upload->loadIntoFile($_FILES[$field->Name], $file); + } catch( ValidationException $e ) { + $validationResult = $e->getResult(); + $form->addErrorMessage($field->Name, $validationResult->message(), 'bad'); + Controller::curr()->redirectBack(); + return; + } // write file to form field $submittedField->UploadedFileID = $file->ID; @@ -734,7 +740,7 @@ JS if($attachments){ foreach($attachments as $file){ if($file->ID != 0) { - $email->attachFile($file->Filename,$file->Filename, HTTP::getMimeType($file->Filename)); + $email->attachFile($file->Filename, $file->Filename, HTTP::get_mime_type($file->Filename)); } } }