add max upload file size config

Bulk upload maximum file size can now be set through
setConfig('maxFileSize', Xbytes )
This commit is contained in:
colymba 2013-03-26 10:48:12 +02:00
parent 2bfd2a8309
commit 60a5e48979
3 changed files with 15 additions and 1 deletions

View File

@ -45,7 +45,8 @@ The available configuration options are:
* 'fieldsNameBlacklist' : array of string referencing the names of fields that wont be available for editing
* 'folderName' : name of the folder where the images should be uploaded
* 'sequentialUploads' : boolean, if true files will be uploaded one by one
* 'maxFileSize' : integer, maximum upload file size in bytes
Each option can be set through the component's method setConfig( $reference, $value )
In addition, some configuration option can be set more specifically via individual methods:
* addFieldNameToBlacklist( $fieldName )

View File

@ -23,6 +23,7 @@ class GridFieldBulkImageUpload implements GridField_HTMLProvider, GridField_URLH
'fieldsClassBlacklist' => array(),
'fieldsNameBlacklist' => array(),
'folderName' => 'bulkUpload',
'maxFileSize' => null,
'sequentialUploads' => false
);
@ -68,6 +69,13 @@ class GridFieldBulkImageUpload implements GridField_HTMLProvider, GridField_URLH
{
$value = array_unique( array_merge($value, $this->forbiddenFieldsClasses) );
}
//makes sure maxFileSize is INT
if ( $reference == 'maxFileSize' && !is_int($value) )
{
user_warning("maxFileSize should be an Integer. Setting it to Auto.", E_USER_ERROR);
$value = null;
}
//sequentialUploads true/false
if ( $reference == 'sequentialUploads' && !is_bool($value) )

View File

@ -219,6 +219,11 @@ class GridFieldBulkImageUpload_Request extends RequestHandler {
$uploadField->setConfig('downloadTemplateName','GridFieldBulkImageUpload_downloadtemplate');
$uploadField->setConfig('sequentialUploads', $this->component->getConfig('sequentialUploads'));
$maxFileSize = $this->component->getConfig('maxFileSize');
if ( $maxFileSize !== null )
{
$uploadField->getValidator()->setAllowedMaxFileSize( $maxFileSize );
}
$uploadField->setConfig('url', $this->Link('upload'));