Crap, that code is dated. Uploads are handled differently in 2.3. Yours would work great in 2.2! :-)
Here's a working example of a resume upload form I'm using on a site right now:
class EmploymentPage_Controller extends Page_Controller
{
public function ResumeForm()
{
return new Form(
$this,
"ResumeForm",
new FieldSet(
new TextField('Name','<span>*</span> Name'),
new TextField('Address'),
new TextField('City'),
new TextField('State'),
new NumericField('Zip'),
new EmailField('Email','<span>*</span> Email'),
new TextField('Phone','<span>*</span> Phone'),
new TextareaField('Message','<span>*</span> Please use the space below to let us know why you are interested in employment','6','40'),
new SWFUploadField(
"ResumeForm",
"Resume",
"<span>*</span> Please attach your most current resume and cover letter (PDF or DOC only).",
array (
'file_types_list' => '*.doc;*.pdf',
'file_queue_limit' => '1',
'browse_button_text' => 'Choose file...',
'upload_url' => $this->Link('handleswfupload'),
'required' => 'true'
)
)
),
new FieldSet(
new FormAction('doResumeSubmit','Submit Application')
),
new RequiredFields('Name','Email','Phone','Message')
);
}
public function handleswfupload()
{
if (isset($_FILES["swfupload_file"]) && is_uploaded_file($_FILES["swfupload_file"]["tmp_name"])) {
$file = new File();
$u = new Upload();
$u->loadIntoFile($_FILES['swfupload_file'], $file, "Resumes");
$file->write();
echo $file->ID;
}
else {
echo ' '; // return something or SWFUpload won't fire uploadSuccess
}
}
public function doResumeSubmit($data,$form)
{
$data = $form->getData();
$to = "myemail@address.com";
$subject = "New Employment Application";
$from = $data['Email'] ? $data['Email'] : "webmaster@mysite.org";
$email = new Email();
$email->ss_template = "EmploymentEmail";
$email->populateTemplate($data);
$email->subject = $subject;
$email->to = $to;
$email->from = $from;
if($_POST['uploaded_files']) {
$file = DataObject::get_by_id("File",$_POST['uploaded_files'][0]);
$email->attachFile(Director::baseFolder() . "/" . $file->Filename, basename($file->Filename));
}
$email->send();
Director::redirect($this->Link('success'));
}
}