mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
b465a46bcc
API CHANGE deprecated some File functions and attributes API CHANGE moved management function from File to Filesystem and added permission checks: sync(), loadContent(), fixfiles(), moverootfilesto() API CHANGE deprecated use of File->loadUploaded() ENHANCEMENT added filesize and extension validation to AssetAdmin and FileField FEATURE added tests for Upload class Merged revisions 47617 via svnmerge from svn://svn.silverstripe.com/silverstripe/modules/cms/branches/2.2.0-mesq ........ r47617 | ischommer | 2008-01-04 19:20:29 +1300 (Fri, 04 Jan 2008) | 5 lines git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@52205 467b73ca-7a2a-4603-9d3b-597d59a354a9
66 lines
1.7 KiB
PHP
Executable File
66 lines
1.7 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* Allows a user to add a field that can be used to upload a file
|
|
|
|
* @package forms
|
|
* @subpackage fieldeditor
|
|
*/
|
|
class EditableFileField extends EditableFormField {
|
|
|
|
// this needs to be moved.
|
|
static $has_one = array(
|
|
"UploadedFile" => "File"
|
|
);
|
|
|
|
/**
|
|
* @see {Upload->allowedMaxFileSize}
|
|
* @var int
|
|
*/
|
|
public static $allowed_max_file_size;
|
|
|
|
/**
|
|
* @see {Upload->allowedExtensions}
|
|
* @var array
|
|
*/
|
|
public static $allowed_extensions = array();
|
|
|
|
static $singular_name = 'File field';
|
|
static $plural_names = 'File fields';
|
|
|
|
function getFormField() {
|
|
if($field = parent::getFormField())
|
|
return $field;
|
|
return new FileField($this->Name, $this->Title, $this->getField('Default'));
|
|
// TODO We can't use the preview feature because FileIFrameField also shows the "From the file store" functionality
|
|
//return new FileIFrameField( $this->Name, $this->Title, $this->getField('Default') );
|
|
}
|
|
|
|
function getSimpleFormField(){
|
|
return new FileField($this->Name, $this->Title, $this->getField('Default'));
|
|
}
|
|
|
|
function createSubmittedField($data, $submittedForm, $fieldClass = "SubmittedFileField") {
|
|
if(!$_FILES[$this->Name])
|
|
return null;
|
|
|
|
$submittedField = new $fieldClass();
|
|
$submittedField->Title = $this->Title;
|
|
$submittedField->Name = $this->Name;
|
|
$submittedField->ParentID = $submittedForm->ID;
|
|
|
|
// create the file from post data
|
|
$upload = new Upload();
|
|
$upload->setAllowedExtensions(self::$allowed_extensions);
|
|
$upload->setAllowedMaxFileSize(self::$allowed_max_file_size);
|
|
|
|
// upload file
|
|
$upload->load($_FILES[$this->Name]);
|
|
|
|
$uploadedFile = $upload->getFile();
|
|
$submittedField->UploadedFileID = $uploadedFile->ID;
|
|
$submittedField->write();
|
|
|
|
return $submittedField;
|
|
}
|
|
}
|
|
?>
|